Example #1
0
        public static Lots getFullInfo(int lotId)
        {
            ApiResponse res = new ApiResponse();

            res.Status = false;
            string url = "lots/" + lotId.ToString();

            res = HTTP.GetJson(url);
            if (res.Status && Util.IsJson(res.RawText))
            {
                Lots RootObject = JsonConvert.DeserializeObject <Lots>(res.RawText, new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                return(RootObject);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        private void addPackageToList(AdjustmentDetail _adjustmentDetail)
        {
            Lots     lotInfo  = null;
            Packages packInfo = null;

            try
            {
                if (_adjustmentDetail.lotId != null)
                {
                    Lots lot = new Lots();
                    lotInfo = lot.getInfo(Convert.ToInt32(_adjustmentDetail.lotId));
                }
            }
            catch (Exception ex) { }
            try
            {
                if (_adjustmentDetail.packageId != null)
                {
                    Packages pack = new Packages();
                    packInfo = pack.getInfo(Convert.ToInt32(_adjustmentDetail.packageId));
                    //Util.Logs(packInfo.packageNumber);
                }
            }
            catch (Exception ex) {  }

            try
            {
                if (_adjustmentDetail.type != "manually")
                {
                    _adjustmentDetail.realQuantity = _adjustmentDetail.theoreticalQuantity;
                }

                DataRow dr = this.dtList.NewRow();
                if (lotInfo != null)
                {
                    dr[COL_LOT] = lotInfo.lotNumber; _adjustmentDetail.traceNumber = lotInfo.lotNumber;
                }
                else
                {
                    dr[COL_LOT] = "";
                }
                if (packInfo != null)
                {
                    dr[COL_PACK] = packInfo.packageNumber; _adjustmentDetail.packageNumber = packInfo.packageNumber;
                }
                else
                {
                    dr[COL_PACK] = "";
                }
                dr[COL_QUANT]             = _adjustmentDetail.realQuantity;
                dr[COL_DEL]               = "Delete";
                dr[COL_PRODUCT_NAME]      = _adjustmentDetail.internalReference;
                dr[COL_BARCODE]           = _adjustmentDetail.barcode;
                dr["created"]             = _adjustmentDetail.created;
                dr["updated"]             = _adjustmentDetail.updated;
                dr["createdBy"]           = _adjustmentDetail.createdBy;
                dr["active"]              = _adjustmentDetail.active;
                dr["id"]                  = _adjustmentDetail.id;
                dr["adjustmentId"]        = _adjustmentDetail.adjustmentId;
                dr["productId"]           = _adjustmentDetail.productId;
                dr["manId"]               = _adjustmentDetail.manId;
                dr["locationId"]          = _LocationInfo.id;
                dr["locationName"]        = _LocationInfo.name;
                dr["theoreticalQuantity"] = _adjustmentDetail.theoreticalQuantity;
                dr["state"]               = _adjustmentDetail.state;
                dr["manPn"]               = _adjustmentDetail.manPn;
                dr["productDescription"]  = _adjustmentDetail.productDescription;
                dr["lotId"]               = _adjustmentDetail.lotId;
                dr["packageId"]           = _adjustmentDetail.packageId;
                this.dtList.Rows.Add(dr);
                this.dgCuonList.DataSource = this.dtList;

                _adjustmentDetail.locationId   = _LocationInfo.id;
                _adjustmentDetail.locationName = _LocationInfo.name;
                _adjustmentDetail.type         = "manually";
                this._ListSpace.Add(_adjustmentDetail);
                this.dgCuonList.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
Example #3
0
        private bool checkScan(string _productName, string _packageId, string type)
        {
            if (_LocationInfo == null)
            {
                MessageBox.Show("Request scan location before scan the package!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                return(false);
            }

            //Check package exists in inventory
            ApiResponse res = new ApiResponse();

            res.Status = false;
            string url = "";
            int    _id = 0; bool isPackage = true;

            if (Util.getTypePackage(_packageId, type) % 2 == 0)
            {
                isPackage = false;
                Lots lotInfo = LotBusiness.getInfo(_packageId);
                if (lotInfo == null)
                {
                    DialogResult mgb = new DialogResult();
                    mgb = MessageBox.Show("Uid is not exists in inventory! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    //if (mgb != DialogResult.Yes) return false;
                    return(false);
                }
                url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";lotId==" + lotInfo.id.ToString();
                _id = lotInfo.id;
            }
            else //if (Util.getTypePackage(_packageId, type) % 2 != 0)
            {
                isPackage = true;
                Packages packageInfo = PackageBusiness.getInfo(_packageId);
                if (packageInfo == null)
                {
                    DialogResult mgb = new DialogResult();
                    mgb = MessageBox.Show("Package is not exists in inventory! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    //if (mgb != DialogResult.Yes) return false;
                    return(false);
                }
                url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";packageId==" + packageInfo.id.ToString();
                _id = packageInfo.id;
            }
            if (url.Length == 0)
            {
                MessageBox.Show("Wrong Package/Unit ID QRCode format !"); return(false);
            }

            try
            {
                res = HTTP.GetJson(url);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Server error: " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                return(false);
            }
            List <AdjustmentDetail> ListDetail;

            if (res.Status && Util.IsJson(res.RawText))
            {
                List <AdjustmentDetail> RootObject = JsonConvert.DeserializeObject <List <AdjustmentDetail> >(res.RawText, new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });

                ListDetail = RootObject as List <AdjustmentDetail>;

                if (checkExistsInTable(_packageId, Convert.ToInt32(type)))
                {
                    return(false);
                }
                else
                {
                    if (ListDetail.Count == 0)
                    {
                        DialogResult mgb = new DialogResult();
                        mgb = MessageBox.Show("Package/UnitID is not exists in inventory adjustment! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        if (mgb != DialogResult.Yes)
                        {
                            return(false);
                        }

                        addPackageFromStock(_id, _packageId, isPackage, _productName, _LocationInfo.barcode, null, 1);

                        //enable button save
                        if (_LocationInfo != null && !btnSave.Enabled)
                        {
                            btnSave.Enabled = true;
                        }
                    }
                    else
                    {
                        if (Util.getTypePackage(_packageId, type) % 2 == 0 || ListDetail.Count == 1)
                        {
                            addPackageToList(ListDetail[0]);
                        }
                        else //Util.getTypePackage(_packageId, type) % 2 != 0
                        {
                            foreach (AdjustmentDetail item in ListDetail)
                            {
                                addPackageToList(item);
                            }
                        }

                        //enable button save
                        if (_LocationInfo != null && !btnSave.Enabled)
                        {
                            btnSave.Enabled = true;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                return(false);
            }
            return(true);
        }
Example #4
0
        private void ScanCode(string dcdData)
        {
            if (dcdData.StartsWith("["))
            {
                #region Scan Package/Unit ID new
                if (this._LocationInfo == null)
                {
                    MessageBox.Show("Request scan location before scan the package!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                try
                {
                    string       scanValue    = dcdData.Replace(System.Environment.NewLine, "").Trim();
                    LabelPackage labelPackage = new LabelPackage(scanValue);

                    //Util.Logs(labelPackage.PackageId);

                    if (labelPackage.PackageId != null && labelPackage.PackageId != "")
                    {
                        //Check package exists in inventory
                        ApiResponse res = new ApiResponse();
                        res.Status = false;
                        string url = "";
                        int    _id = 0; bool isPackage = true;
                        if (Util.getTypePackage(labelPackage.PackageId, null) % 2 == 0)
                        {
                            isPackage = false;
                            Lots lot     = new Lots();
                            Lots lotInfo = lot.getInfo(labelPackage.PackageId);
                            if (lotInfo == null)
                            {
                                MessageBox.Show("Unit ID is not exists in inventory !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }
                            else
                            {
                                url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";lotId==" + lotInfo.id.ToString();
                                _id = lotInfo.id;
                            }
                        }
                        else if (Util.getTypePackage(labelPackage.PackageId, null) % 2 != 0)
                        {
                            isPackage = true;
                            Packages package     = new Packages();
                            Packages packageInfo = package.getInfo(labelPackage.PackageId);
                            if (packageInfo == null)
                            {
                                MessageBox.Show("Package is not exists in inventory !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }
                            else
                            {
                                url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";packageId==" + packageInfo.id.ToString();
                                _id = packageInfo.id;
                            }
                        }
                        if (url.Length == 0)
                        {
                            MessageBox.Show("Wrong Package/Unit ID QRCode format !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }

                        try
                        {
                            res = HTTP.GetJson(url);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                        List <AdjustmentDetail> ListDetail;
                        if (res.Status && Util.IsJson(res.RawText))
                        {
                            List <AdjustmentDetail> RootObject = JsonConvert.DeserializeObject <List <AdjustmentDetail> >(res.RawText, new JsonSerializerSettings
                            {
                                NullValueHandling = NullValueHandling.Ignore
                            });

                            ListDetail = RootObject as List <AdjustmentDetail>;

                            if (checkExistsInTable(labelPackage.PackageId))
                            {
                                return;
                            }
                            else
                            {
                                if (ListDetail.Count == 0)
                                {
                                    DialogResult mgb = new DialogResult();
                                    mgb = MessageBox.Show("Package/Unit ID is not exists in inventory adjustment! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                    if (mgb != DialogResult.Yes)
                                    {
                                        return;
                                    }

                                    addPackageFromStock(_id, labelPackage.PackageId, isPackage, labelPackage.ProductName, _LocationInfo.barcode, null, 0);
                                    //addPackageToList(labelPackage.PackageId, 0, labelPackage.ProductName, _LocationInfo.barcode);

                                    //enable button save
                                    if (_LocationInfo != null && !btnSave.Enabled)
                                    {
                                        btnSave.Enabled = true;
                                    }
                                }
                                else
                                {
                                    if (labelPackage.PackageId.StartsWith(PREFIX_LOT) || ListDetail.Count == 1)
                                    {
                                        addPackageToList(ListDetail[0]);
                                    }
                                    else if (labelPackage.PackageId.StartsWith(PREFIX_PACK))
                                    {
                                        foreach (AdjustmentDetail item in ListDetail)
                                        {
                                            addPackageToList(item);
                                        }
                                    }

                                    //enable button save
                                    if (_LocationInfo != null && !btnSave.Enabled)
                                    {
                                        btnSave.Enabled = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong Package/Unit ID QRCode format !");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error scan!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                #endregion
            }
            else if (dcdData.Trim().StartsWith("PN:"))
            {
                #region Scan Package/Unit ID old
                if (_LocationInfo == null)
                {
                    MessageBox.Show("Request scan location before scan the package!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                try
                {
                    string  scanValue = dcdData.Replace(System.Environment.NewLine, "").Trim();
                    TemCuon temCuon   = new TemCuon(scanValue);

                    if (temCuon.IdCuon != null && temCuon.IdCuon != "")
                    {
                        //Check package exists in inventory
                        ApiResponse res = new ApiResponse();
                        res.Status = false;
                        string url = "";
                        int    _id = 0; bool isPackage = true;

                        if (Convert.ToInt32(temCuon.Type) == 0)
                        {
                            isPackage = false;
                            Lots lot     = new Lots();
                            Lots lotInfo = lot.getInfo(temCuon.IdCuon);
                            if (lotInfo == null)
                            {
                                DialogResult mgb = new DialogResult();
                                mgb = MessageBox.Show("Uid is not exists in inventory! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                if (mgb != DialogResult.Yes)
                                {
                                    return;
                                }
                                if (checkExistsInTable(temCuon.IdCuon, Convert.ToInt32(temCuon.Type)))
                                {
                                    return;
                                }
                                addPackageToList(null, temCuon.IdCuon, Convert.ToDouble(temCuon.SoLuong), temCuon.VnptPn, _LocationInfo.barcode, temCuon.Type);
                            }
                            url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";lotId==" + lotInfo.id.ToString();
                            _id = lotInfo.id;
                        }
                        else if (Convert.ToInt32(temCuon.Type) == 1)
                        {
                            isPackage = true;
                            Packages package     = new Packages();
                            Packages packageInfo = package.getInfo(temCuon.IdCuon);
                            if (packageInfo == null)
                            {
                                DialogResult mgb = new DialogResult();
                                mgb = MessageBox.Show("Package is not exists in inventory! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                if (mgb != DialogResult.Yes)
                                {
                                    return;
                                }
                                if (checkExistsInTable(temCuon.IdCuon, Convert.ToInt32(temCuon.Type)))
                                {
                                    return;
                                }
                                addPackageToList(temCuon.IdCuon, null, Convert.ToDouble(temCuon.SoLuong), temCuon.VnptPn, _LocationInfo.barcode, temCuon.Type);
                            }
                            url = "adjustment-details/search?query=adjustmentId==" + _Adjustment.id.ToString() + ";packageId==" + packageInfo.id.ToString();
                            _id = packageInfo.id;
                        }
                        if (url.Length == 0)
                        {
                            MessageBox.Show("Wrong Package/Unit ID QRCode format !"); return;
                        }

                        try
                        {
                            res = HTTP.GetJson(url);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                        List <AdjustmentDetail> ListDetail;
                        if (res.Status && Util.IsJson(res.RawText))
                        {
                            List <AdjustmentDetail> RootObject = JsonConvert.DeserializeObject <List <AdjustmentDetail> >(res.RawText, new JsonSerializerSettings
                            {
                                NullValueHandling = NullValueHandling.Ignore
                            });

                            ListDetail = RootObject as List <AdjustmentDetail>;

                            if (checkExistsInTable(temCuon.IdCuon, Convert.ToInt32(temCuon.Type)))
                            {
                                return;
                            }
                            else
                            {
                                if (ListDetail.Count == 0)
                                {
                                    DialogResult mgb = new DialogResult();
                                    mgb = MessageBox.Show("Package/Unit ID is not exists in inventory adjustment! Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                    if (mgb != DialogResult.Yes)
                                    {
                                        return;
                                    }

                                    addPackageFromStock(_id, temCuon.IdCuon, isPackage, temCuon.VnptPn, _LocationInfo.barcode, temCuon.Type, Convert.ToDouble(temCuon.SoLuong));
                                    //addPackageToList(temCuon.IdCuon, 0, temCuon.VnptPn, _LocationInfo.barcode, Convert.ToInt32(temCuon.Type));

                                    //enable button save
                                    if (_LocationInfo != null && !btnSave.Enabled)
                                    {
                                        btnSave.Enabled = true;
                                    }
                                }
                                else
                                {
                                    if (Convert.ToInt32(temCuon.Type) == 0 || ListDetail.Count == 1)
                                    {
                                        addPackageToList(ListDetail[0]);
                                    }
                                    else if (Convert.ToInt32(temCuon.Type) == 1)
                                    {
                                        foreach (AdjustmentDetail item in ListDetail)
                                        {
                                            addPackageToList(item);
                                        }
                                    }

                                    //enable button save
                                    if (_LocationInfo != null && !btnSave.Enabled)
                                    {
                                        btnSave.Enabled = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Server error !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Wrong Package/Unit ID QRCode format !");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error scan!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
                #endregion
            }
            else if (Util.OnlyHexInString(dcdData.Trim()))
            {
                #region scan serial number

                string SerialNumber = dcdData.Trim();
                checkScan(null, SerialNumber, null);

                #endregion
            }
            else
            {
                #region Scan location
                locationBarcode = dcdData.Replace(System.Environment.NewLine, "").Trim();
                try
                {
                    ApiResponse res = new ApiResponse();
                    res.Status = false;

                    string url   = "locations/check-child";
                    var    param = new
                    {
                        locationId = this._Adjustment.locationId,
                        barcode    = locationBarcode
                    };
                    res = HTTP.Post(url, param);
                    if (res.Status)
                    {
                        if (Convert.ToBoolean(res.RawText))
                        {
                            if (_LocationInfo != null)
                            {
                                DialogResult mgb = new DialogResult();
                                mgb = MessageBox.Show("Are you sure you want to update new scan location?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                if (mgb != DialogResult.Yes)
                                {
                                    return;
                                }
                            }

                            _LocationInfo = getLocationInfo(locationBarcode);
                            if (_LocationInfo == null)
                            {
                                return;
                            }

                            this.lblLocationBarcode.Text = _LocationInfo.name;

                            //enable button save
                            if (this.dtList.Rows.Count > 0 && !btnSave.Enabled)
                            {
                                btnSave.Enabled = true;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Location is not exists in adjustment name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            //btnSave.Enabled = false;
                            //this.dtList.Rows.Clear();
                            //this.dgCuonList.Refresh();
                            this.locationBarcode = null;
                            //this.lblLocationBarcode.Text = null;
                        }
                    }
                    else
                    {
                        //btnSave.Enabled = false;
                        //this.dtList.Rows.Clear();
                        //this.dgCuonList.Refresh();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error during load location information !");
                }
                #endregion
            }
        }
Example #5
0
        private bool checkScan(string _packageId, string type)
        {
            if (Util.getTypePackage(_packageId, type) % 2 == 0)
            {
                #region Scan uid
                try
                {
                    if (_packageId != null && _packageId != "")
                    {
                        if (checkReservedInOtherList(_packageId, false))
                        {
                            MessageBox.Show("Package/Uid already exists in another reserved list!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return(false);
                        }

                        DataRow[] rs_package = dtList.Select(COL_LOT_ID + " = '" + _packageId + "'");
                        if (rs_package.Length > 0)
                        {
                            //DialogResult mgb = new DialogResult();
                            //mgb = MessageBox.Show("Package not exists in list !", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            //if (mgb == DialogResult.Yes)
                            //{
                            //    dr = dtList.Select("internalReference = '" + labelPackage.ProductName + "' AND " + COL_ID + " = '" + labelPackage.PackageId + "'").FirstOrDefault();
                            //    if(dr == null)
                            //        addPackageNotInList(labelPackage.ProductName, labelPackage.PackageId);
                            //}

                            MessageBox.Show("Unit ID " + _packageId + " already exists in the list !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            return(false);
                        }
                        else
                        {
                            //Validate Unit ID
                            Lots lot     = new Lots();
                            Lots lotInfo = lot.getInfo(_packageId);
                            if (lotInfo == null)
                            {
                                MessageBox.Show("Unit ID " + _packageId + " is not exists in inventory !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return(false);
                            }

                            Packages PackageInfo = validateLot(lotInfo.id);
                            if (PackageInfo == null)
                            {
                                return(false);
                            }

                            if (PackageInfo.packageNumber == null)
                            {
                                if (this.dtList.Rows.Count == 0)
                                {
                                    addPackageToList("", _packageId);
                                }
                                else
                                {
                                    DataRow[] rs = dtList.Select(COL_PACK_ID + " = ''");
                                    if (rs.Length > 0)
                                    {
                                        addPackageToList("", _packageId);
                                    }
                                    else
                                    {
                                        if (Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]).Length > 0)
                                        {
                                            MessageBox.Show("Request scan unit ID in package " + Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]));
                                        }
                                        else
                                        {
                                            MessageBox.Show("Request scan free unit ID !");
                                        }
                                        return(false);
                                    }
                                }
                            }
                            else
                            {
                                if (this.dtList.Rows.Count == 0)
                                {
                                    addPackageToList(PackageInfo.packageNumber, _packageId);
                                }
                                else
                                {
                                    DataRow[] rs = dtList.Select(COL_PACK_ID + " = '" + PackageInfo.packageNumber + "'");
                                    if (rs.Length > 0)
                                    {
                                        addPackageToList(PackageInfo.packageNumber, _packageId);
                                    }
                                    else
                                    {
                                        if (Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]).Length > 0)
                                        {
                                            MessageBox.Show("Request scan unit ID in package " + Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]));
                                        }
                                        else
                                        {
                                            MessageBox.Show("Request scan free unit ID !");
                                        }
                                        return(false);
                                    }
                                }
                            }

                            if (DestPackageNumber != null && DestPackageNumber.Trim().Length > 0 && !btnSave.Enabled)
                            {
                                //enable button save
                                btnSave.Enabled  = true;
                                btnClear.Enabled = true;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Error scan!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.InnerException.ToString());
                    //MessageBox.Show("Error during loading information !", "Chu y", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return(false);
                }
                #endregion
            }
            else //if (Util.getTypePackage(_packageId, type) % 2 != 0)
            {
                #region Scan package
                if (DestPackageNumber != null && DestPackageNumber.Length > 0)
                {
                    DialogResult mgb = new DialogResult();
                    mgb = MessageBox.Show("Are you sure you want to update the package number?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    if (mgb != DialogResult.Yes)
                    {
                        return(false);
                    }
                }

                if (!checkExistsPackage(_packageId))
                {
                    return(false);
                }

                if (checkReservedInOtherList(_packageId, true))
                {
                    MessageBox.Show("Package/Uid already exists in another reserved list!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return(false);
                }

                DestPackageNumber         = _packageId;
                txtDestPackageNumber.Text = DestPackageNumber;

                if (this.dtList.Rows.Count > 0 && !btnSave.Enabled)
                {
                    //enable button save
                    btnSave.Enabled  = true;
                    btnClear.Enabled = true;
                }
                #endregion
            }
            return(true);
        }
Example #6
0
        private void ScanCode(string dcdData)
        {
            //Obtain the string and code id.
            //MessageBox.Show(dcdData);
            if (dcdData.StartsWith("["))
            {
                #region New label
                LabelPackage labelPackage = null;
                try
                {
                    labelPackage = new LabelPackage(dcdData.Trim());
                }
                catch
                {
                    MessageBox.Show("Wrong Package/UnitID QRCode format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                if (labelPackage.PackageId.StartsWith(PREFIX_LOT))
                {
                    #region Scan uid
                    try
                    {
                        if (labelPackage.PackageId != null && labelPackage.PackageId != "")
                        {
                            if (checkReservedInOtherList(labelPackage.PackageId, false))
                            {
                                MessageBox.Show("Package/Uid already exists in another reserved list!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }

                            DataRow[] rs_package = dtList.Select(COL_LOT_ID + " = '" + labelPackage.PackageId + "'");
                            if (rs_package.Length > 0)
                            {
                                //DialogResult mgb = new DialogResult();
                                //mgb = MessageBox.Show("Package not exists in list !", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                //if (mgb == DialogResult.Yes)
                                //{
                                //    dr = dtList.Select("internalReference = '" + labelPackage.ProductName + "' AND " + COL_ID + " = '" + labelPackage.PackageId + "'").FirstOrDefault();
                                //    if(dr == null)
                                //        addPackageNotInList(labelPackage.ProductName, labelPackage.PackageId);
                                //}

                                MessageBox.Show("Unit ID " + labelPackage.PackageId + " already exists in the list !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }
                            else
                            {
                                //Validate Unit ID
                                Lots lot     = new Lots();
                                Lots lotInfo = lot.getInfo(labelPackage.PackageId);
                                if (lotInfo == null)
                                {
                                    MessageBox.Show("Unit ID " + labelPackage.PackageId + " is not exists in inventory !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                    return;
                                }

                                Packages PackageInfo = validateLot(lotInfo.id);
                                if (PackageInfo == null)
                                {
                                    return;
                                }

                                if (PackageInfo.packageNumber == null)
                                {
                                    if (this.dtList.Rows.Count == 0)
                                    {
                                        addPackageToList("", labelPackage.PackageId);
                                    }
                                    else
                                    {
                                        DataRow[] rs = dtList.Select(COL_PACK_ID + " = ''");
                                        if (rs.Length > 0)
                                        {
                                            addPackageToList("", labelPackage.PackageId);
                                        }
                                        else
                                        {
                                            if (Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]).Length > 0)
                                            {
                                                MessageBox.Show("Request scan unit ID in package " + Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]));
                                            }
                                            else
                                            {
                                                MessageBox.Show("Request scan free unit ID !");
                                            }
                                            return;
                                        }
                                    }
                                }
                                else
                                {
                                    if (this.dtList.Rows.Count == 0)
                                    {
                                        addPackageToList(PackageInfo.packageNumber, labelPackage.PackageId);
                                    }
                                    else
                                    {
                                        DataRow[] rs = dtList.Select(COL_PACK_ID + " = '" + PackageInfo.packageNumber + "'");
                                        if (rs.Length > 0)
                                        {
                                            addPackageToList(PackageInfo.packageNumber, labelPackage.PackageId);
                                        }
                                        else
                                        {
                                            if (Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]).Length > 0)
                                            {
                                                MessageBox.Show("Request scan unit ID in package " + Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]));
                                            }
                                            else
                                            {
                                                MessageBox.Show("Request scan free unit ID !");
                                            }
                                            return;
                                        }
                                    }
                                }

                                if (DestPackageNumber != null && DestPackageNumber.Trim().Length > 0 && !btnSave.Enabled)
                                {
                                    //enable button save
                                    btnSave.Enabled  = true;
                                    btnClear.Enabled = true;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Error scan!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        }
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.InnerException.ToString());
                        //MessageBox.Show("Error during loading information !", "Chu y", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }
                    #endregion
                }
                else if (labelPackage.PackageId.StartsWith(PREFIX_PACK))
                {
                    #region Scan package
                    if (DestPackageNumber != null && DestPackageNumber.Length > 0)
                    {
                        DialogResult mgb = new DialogResult();
                        mgb = MessageBox.Show("Are you sure you want to update the package number?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        if (mgb != DialogResult.Yes)
                        {
                            return;
                        }
                    }

                    if (!checkExistsPackage(labelPackage.PackageId))
                    {
                        return;
                    }

                    if (checkReservedInOtherList(labelPackage.PackageId, true))
                    {
                        MessageBox.Show("Package/Uid already exists in another reserved list!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    DestPackageNumber         = labelPackage.PackageId;
                    txtDestPackageNumber.Text = DestPackageNumber;

                    if (this.dtList.Rows.Count > 0 && !btnSave.Enabled)
                    {
                        //enable button save
                        btnSave.Enabled  = true;
                        btnClear.Enabled = true;
                    }
                    #endregion
                }
                else
                {
                    MessageBox.Show("Wrong Package/UnitID QRCode format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }
                #endregion
            }
            else if (dcdData.Trim().StartsWith("PN:"))
            {
                #region Old label
                TemCuon labelPackage = null;
                try
                {
                    labelPackage = new TemCuon(dcdData.Trim());
                }
                catch { MessageBox.Show("Wrong Package/UnitID QRCode format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; }

                if (Convert.ToInt32(labelPackage.Type) == 0)
                {
                    #region Scan Unit ID
                    try
                    {
                        if (labelPackage.IdCuon != null && labelPackage.IdCuon != "")
                        {
                            if (checkReservedInOtherList(labelPackage.IdCuon, false))
                            {
                                MessageBox.Show("Package/Uid already exists in another reserved list!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }

                            DataRow[] rs_package = dtList.Select(COL_LOT_ID + " = '" + labelPackage.IdCuon + "'");
                            if (rs_package.Length > 0)
                            {
                                MessageBox.Show("Unit ID " + labelPackage.IdCuon + " already exists in the list !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                return;
                            }
                            else
                            {
                                //Validate Unit ID
                                Lots lot     = new Lots();
                                Lots lotInfo = lot.getInfo(labelPackage.IdCuon);
                                if (lotInfo == null)
                                {
                                    MessageBox.Show("Unit ID " + labelPackage.IdCuon + " is not exists in inventory !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                                    return;
                                }

                                Packages PackageInfo = validateLot(lotInfo.id);
                                if (PackageInfo == null)
                                {
                                    return;
                                }

                                if (PackageInfo.packageNumber == null)
                                {
                                    if (this.dtList.Rows.Count == 0)
                                    {
                                        addPackageToList("", labelPackage.IdCuon);
                                    }
                                    else
                                    {
                                        DataRow[] rs = dtList.Select(COL_PACK_ID + " = ''");
                                        if (rs.Length > 0)
                                        {
                                            addPackageToList("", labelPackage.IdCuon);
                                        }
                                        else
                                        {
                                            if (Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]).Length > 0)
                                            {
                                                MessageBox.Show("Request scan unit ID in package " + Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]));
                                            }
                                            else
                                            {
                                                MessageBox.Show("Request scan free unit ID !");
                                            }
                                            return;
                                        }
                                    }
                                }
                                else
                                {
                                    if (this.dtList.Rows.Count == 0)
                                    {
                                        addPackageToList(PackageInfo.packageNumber, labelPackage.IdCuon);
                                    }
                                    else
                                    {
                                        DataRow[] rs = dtList.Select(COL_PACK_ID + " = '" + PackageInfo.packageNumber + "'");
                                        if (rs.Length > 0)
                                        {
                                            addPackageToList(PackageInfo.packageNumber, labelPackage.IdCuon);
                                        }
                                        else
                                        {
                                            if (Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]).Length > 0)
                                            {
                                                MessageBox.Show("Request scan unit ID in package " + Convert.ToString(this.dtList.Rows[0][COL_PACK_ID]));
                                            }
                                            else
                                            {
                                                MessageBox.Show("Request scan free unit ID !");
                                            }
                                            return;
                                        }
                                    }
                                }

                                if (DestPackageNumber != null && DestPackageNumber.Trim().Length > 0 && !btnSave.Enabled)
                                {
                                    //enable button save
                                    btnSave.Enabled  = true;
                                    btnClear.Enabled = true;
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Error scan!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        }
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.InnerException.ToString());
                        //MessageBox.Show("Error during loading information !", "Chu y", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }
                    #endregion
                }
                else if (Convert.ToInt32(labelPackage.Type) == 1)
                {
                    #region Scan package
                    if (DestPackageNumber != null && DestPackageNumber.Length > 0)
                    {
                        DialogResult mgb = new DialogResult();
                        mgb = MessageBox.Show("Are you sure you want to update the package number?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        if (mgb != DialogResult.Yes)
                        {
                            return;
                        }
                    }

                    if (!checkExistsPackage(labelPackage.IdCuon))
                    {
                        return;
                    }

                    if (checkReservedInOtherList(labelPackage.IdCuon, true))
                    {
                        MessageBox.Show("Package/Uid already exists in another reserved list!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                        return;
                    }

                    DestPackageNumber         = labelPackage.IdCuon;
                    txtDestPackageNumber.Text = DestPackageNumber;

                    if (this.dtList.Rows.Count > 0 && !btnSave.Enabled)
                    {
                        //enable button save
                        btnSave.Enabled  = true;
                        btnClear.Enabled = true;
                    }
                    #endregion
                }
                else
                {
                    MessageBox.Show("Wrong Package/UnitID QRCode format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return;
                }
                #endregion
            }
            else if (Util.OnlyHexInString(dcdData.Trim()))
            {
                #region Serial number

                string SerialNumber = dcdData.Trim();
                checkScan(SerialNumber, null);

                #endregion
            }
            else
            {
                MessageBox.Show("Wrong Package/UnitID QRCode format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return;
            }
        }