示例#1
0
        private static Good GoodFabric(ShopItemInfo item)
        {
            Good good = null;

            var ids = item.Code.Split(new[] { "_" }, StringSplitOptions.RemoveEmptyEntries);

            if (ids.Count() != 2)
            {
                return(null);
            }

            int    kind = int.Parse(ids[0]);
            string code = ids[1];

            switch (kind)
            {
            case 0:
                good = new GoodShop()
                {
                    UnitName = item.Measure, RestQuantity = item.RestQuantity, Quantity = item.Quantity
                };
                break;

            case 1:
                good = new GoodService()
                {
                    UnitName = item.Measure, Quantity = item.Quantity
                };
                break;

            case 2:
                good = new GoodFuel()
                {
                    Amount = item.Quantity
                };
                break;

            default:
                return(null);

                break;
            }
            good.Kind = kind;
            good.Item = code;
            good.InternalGroupName = item.GroupName;
            good.Name = item.Name;

            good.Price = item.BasePrice;

            good.TaxID             = item.TaxNumber;
            good.InternalSectionId = item.Section;

            good.Discount = item.Discount;

            return(good);
        }
示例#2
0
        private static Good ParseGood(string src)
        {
            Good result = null;
            int  kind   = -1;

            if (!src.StartsWith("{") || !src.EndsWith("}"))
            {
                return(null);
            }
            src = src.Substring(1, src.Count() - 2);

            var parameters = src.Split(new[] { ",\"" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var pair in parameters)
            {
                var values = pair.Split(new[] { "\":" }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Count() != 2)
                {
                    continue;
                }

                var nm = values[0];
                if (nm.StartsWith("\""))
                {
                    nm = nm.Substring(1, nm.Count() - 1);
                }
                if (nm.EndsWith("\""))
                {
                    nm = nm.Substring(0, nm.Count() - 1);
                }

                var val = values[1];
                if (val.StartsWith("\""))
                {
                    val = val.Substring(1, val.Count() - 1);
                }
                if (val.EndsWith("\""))
                {
                    val = val.Substring(0, val.Count() - 1);
                }


                switch (nm)
                {
                case "Kind":
                    kind = int.Parse(val);
                    switch (kind)
                    {
                    case 0:
                        result = new GoodShop();
                        break;

                    case 1:
                        result = new GoodService();
                        break;

                    case 2:
                        result = new GoodFuel();
                        break;
                    }
                    result.Kind = kind;
                    break;

                case "Item":
                    if (result != null)
                    {
                        result.Item = val == "null" ? null : val;
                    }
                    break;

                case "Name":
                    if (result != null)
                    {
                        result.Name = val == "null" ? null : val;
                    }
                    break;

                case "DepartmentId":
                    if (result != null)
                    {
                        result.DepartmentId = int.Parse(val);
                    }
                    break;

                case "TaxID":
                    if (result != null)
                    {
                        result.TaxID = int.Parse(val);
                    }
                    break;

                case "Price":
                    if (result != null)
                    {
                        result.Price = int.Parse(val);
                    }
                    break;

                case "BatchDate":
                {
                    if ((result as GoodShop) != null)
                    {
                        (result as GoodShop).BatchDate = val == "null" ? null : val;
                    }
                    break;
                }

                case "GroupId":
                    if ((result as GoodShop) != null)
                    {
                        (result as GoodShop).GroupId = int.Parse(val);
                    }
                    if ((result as GoodService) != null)
                    {
                        (result as GoodService).GroupId = int.Parse(val);
                    }
                    break;

                case "UnitName":
                    if ((result as GoodShop) != null)
                    {
                        (result as GoodShop).UnitName = val == "null" ? null : val;
                    }
                    if ((result as GoodService) != null)
                    {
                        (result as GoodService).UnitName = val == "null" ? null : val;
                    }
                    break;

                case "RestQuantity":
                    if ((result as GoodShop) != null)
                    {
                        (result as GoodShop).RestQuantity = int.Parse(val);
                    }
                    break;

                case "ReturnDepartmentId":
                    if ((result as GoodFuel) != null)
                    {
                        (result as GoodFuel).ReturnDepartmentId = int.Parse(val);
                    }
                    break;

                case "ArbitraryPrice":
                    if ((result as GoodFuel) != null)
                    {
                        (result as GoodFuel).ArbitraryPrice = bool.Parse(val);
                    }
                    break;

                case "Complex":
                    if ((result as GoodFuel) != null)
                    {
                        (result as GoodFuel).Complex = bool.Parse(val);
                    }
                    break;
                }
            }
            result.InternalGroupId = result.Kind + "_" + result.Item;
            return(result);
        }