Beispiel #1
0
        public void Search()
        {
            try
            {
                isBarCode = false;
                string costumeID = this.Text.Trim();
                if (string.IsNullOrEmpty(costumeID))
                {
                    if (this.CostumeSelected != null)
                    {
                        curItem = null;
                        this.CostumeSelected(curItem, true);
                    }
                    return;
                }
                if (CommonGlobalUtil.EngineUnconnectioned(this))
                {
                    return;
                }
                //条形码,先根据条形码获取款号
                //List<BarCode> barCodes = CommonGlobalCache.BarCodeList?.FindAll(t => t.BarCodeValue.ToUpper().Equals(costumeID.ToUpper()));

                ////,条形码为一条,找到这个款号
                //if (barCodes != null && barCodes.Count == 1)
                //{
                //    costumeID = barCodes[0].CostumeID;
                //    this.Text = barCodes[0].BarCodeValue;
                //    isBarCode = true;
                //}
                if (costumeID.Length == 15)
                {
                    BarCode4Costume costume = CommonGlobalUtil.GetBarCode(costumeID);
                    if (costume != null)
                    {
                        costumeID    = costume.CostumeID;
                        SkinTxt.Text = costume.BarCode;
                        isBarCode    = true;
                    }
                }

                List <Costume> resultList = CommonGlobalCache.CostumeList.FindAll(t => (t.ID.ToUpper().Contains(costumeID.ToUpper())));
                if (filterValid)
                {
                    resultList = resultList.FindAll(t => t.IsValid);
                }

                /*  CostumeItem t = new CostumeItem();
                 *
                 * List<CostumeItem> resultList = CommonGlobalCache.ServerProxy.GetCostumeStoreList(new CostumeStoreListPara()
                 * {
                 *    CostumeID = costumeID,
                 *    ShopID = this.ShopID,
                 *    IsOnlyShowValid = filterValid
                 * });
                 *
                 *
                 * //有供应商则过滤供应商
                 * if (SupplierID != null && resultList != null)
                 * {
                 *    resultList = resultList.FindAll(i => i.Costume.SupplierID == SupplierID);
                 * }*/
                if (resultList == null || resultList.Count == 0)
                {
                    if (this.CostumeSelected != null)
                    {
                        curItem = null;
                        this.CostumeSelected(curItem, true);
                    }
                    this.Text = "";
                    return;
                }
                if (resultList.Count == 1)
                {
                    if (!isBarCode)
                    {
                        this.Text = resultList[0].ID;
                    }
                    if (this.CostumeSelected != null)
                    {
                        Costume curCostume = resultList[0];
                        curItem = null; //根据条件获取库存信息

                        List <CostumeItem> selectResultItem = CommonGlobalCache.ServerProxy.GetCostumeStoreList(new CostumeStoreListPara()
                        {
                            CostumeID       = resultList[0].ID,
                            ShopID          = this.ShopID,
                            IsOnlyShowValid = filterValid,
                            IsAccurateQuery = true,
                        });

                        if (SupplierID != null && resultList != null)
                        {
                            selectResultItem = selectResultItem.FindAll(i => i.Costume.SupplierID == SupplierID);
                        }
                        if (selectResultItem.Count > 0)
                        {
                            this.CostumeSelected(selectResultItem[0], true);
                        }
                        else
                        {
                            this.Text = "";
                        }
                    }
                }
                else
                {
                    CostumeFromShopForm costumeForm = new CostumeFromShopForm(resultList, costumeID, ShopID, FilterValid, SupplierID);

                    if (costumeForm.ShowDialog() == DialogResult.OK)
                    {
                        if (costumeForm.Result == null)
                        {
                            return;
                        }
                        this.Text = costumeForm.Result.Costume.ID;
                        curItem   = costumeForm.Result;
                        CostumeSelected?.Invoke(curItem, true);
                    }
                }
            }
            catch (Exception ee)
            {
                ShowError(ee);
            }
            finally
            {
                UnLockPage();
            }
        }
        private void SkinTxt_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }
            try
            {
                isBarCode = false;
                string costumeID = this.SkinTxt.Text.Trim();
                if (string.IsNullOrEmpty(costumeID))
                {
                    if (this.CostumeSelected != null)
                    {
                        this.CostumeSelected(null);
                    }
                    return;
                }
                if (CommonGlobalUtil.EngineUnconnectioned(this))
                {
                    return;
                }
                //条形码,先根据条形码获取款号
                //List<BarCode> barCodes = CommonGlobalCache.BarCodeList?.FindAll(t => t.BarCodeValue.ToUpper().Equals(costumeID.ToUpper()));

                ////,条形码为一条,找到这个款号
                //if (barCodes != null && barCodes.Count == 1)
                //{
                //    costumeID = barCodes[0].CostumeID;
                //    SkinTxt.Text = barCodes[0].BarCodeValue;
                //    isBarCode = true;
                //}
                if (costumeID.Length == 15)
                {
                    BarCode4Costume costume = CommonGlobalUtil.GetBarCode(costumeID);
                    if (costume != null)
                    {
                        costumeID    = costume.CostumeID;
                        SkinTxt.Text = costume.BarCode;
                        isBarCode    = true;
                    }
                }


                List <CostumeItem> resultList = CommonGlobalCache.ServerProxy.GetCostumeStoreList(
                    new CostumeStoreListPara()
                {
                    CostumeID       = costumeID,
                    ShopID          = CommonGlobalCache.CurrentShopID,
                    IsOnlyShowValid = filterValid
                });

                if (resultList == null || resultList.Count == 0)
                {
                    this.CostumeSelected?.Invoke(null);
                    this.SkinTxt.Text = "";
                    return;
                }

                if (resultList.Count == 1)
                {
                    resultList[0].Costume.BrandName    = CommonGlobalCache.GetBrandName(resultList[0].Costume.BrandID);
                    resultList[0].Costume.SupplierName = CommonGlobalCache.GetSupplierName(resultList[0].Costume.SupplierID);
                    if (resultList[0].CostumeStoreList != null)
                    {
                        foreach (var item in resultList[0].CostumeStoreList)
                        {
                            item.CostumeName = resultList[0].Costume.Name;
                            item.BrandName   = resultList[0].Costume.BrandName;
                            item.Price       = resultList[0].Costume.Price;
                            item.CostPrice   = resultList[0].Costume.CostPrice;
                        }
                    }


                    if (!isBarCode)
                    {
                        this.SkinTxt.Text = resultList[0].Costume.ID;
                    }
                    if (this.CostumeSelected != null)
                    {
                        this.CostumeSelected(resultList[0]);
                    }
                }
                else
                {
                    CostumeFromShopForm costumeForm = new CostumeFromShopForm(resultList, costumeID, CommonGlobalCache.CurrentShopID, filterValid);
                    //   costumeForm.Hide();
                    // costumeForm.CostumeSelected += CostumeForm_CostumeSelected;
                    if (costumeForm.ShowDialog() == DialogResult.OK)
                    {
                        if (costumeForm.Result == null)
                        {
                            return;
                        }
                        this.SkinTxt.Text = costumeForm.Result.Costume.ID;
                        CostumeSelected?.Invoke(costumeForm.Result);
                    }
                }
            }
            catch (Exception ee)
            {
                ShowError(ee);
            }
            finally
            {
                UnLockPage();
            }
        }