コード例 #1
0
        public Goods CallRegisterGoodsPopup(Product product, WarehouseContext dbcontext)
        {
            Goods newGoods = null;
            var window = new NotifyWindow();
            window.Width = 400;
            window.Height = 600;
            window.Title = "添加货物";

            var formControl = FormControlHelper.CreateFormControl();
            var goods = new Goods();
            goods.Product = product;
            goods.Name = product.Name;
            goods.State = GoodsState.Inbound;
            goods.GoodsCode = DateTime.Now.ToString("yyyyMMddHHmmss")+"001";

            formControl.CreateControlCallback = (cx, ctl) =>
            {
                if (cx.ControlType == ControlType.Editable)
                {
                    switch (cx.PropertyInfo.Name)
                    {
                        case "Product":
                            var tb = new TextBox();
                            tb.Text = product.Name;
                            tb.Style = Application.Current.Resources["editctl_TextBox"] as Style;
                            tb.IsEnabled = false;
                            CustomValidation.SetValidationOptOut(tb);
                            return tb;
                        case "GoodsCode":
                            ctl.IsEnabled = false;
                            return ctl;
                    }
                }
                return ctl;
            };

            formControl.RenderForm(goods, false);
            formControl.ConfirmButton.Content = "添加";
            formControl.SubmitCallback = d =>
            {
                try
                {
                    newGoods = d as Goods;
                    newGoods.InboundDate=DateTime.Now;
                    dbcontext.Goods.Add(newGoods);
                    window.Close();
                }
                catch (Exception ex)
                {
                    window.ShowNotificationMessage("添加货物失败,请重试。");
                }
            };
            window.MyContent = formControl;
            window.ShowDialog();
            return newGoods;
        }
コード例 #2
0
        public static void AddSampleData()
        {
            using (var dbcontext = new WarehouseContext())
            {
                try
                {
                    var user1 = new User()
                    {
                        Name = "二娃",
                        Username = "******",
                        Password = "******",
                        IdentificationNumber = "310392198305114344",
                        PhoneNumber = "13543776409",
                        Company = "梁山",
                        Department = "库房管理部",
                        Memo = "(●'◡'●)"
                    };
                    dbcontext.Users.Add(user1);

                    var tg = new TagGroup()
                    {
                        Name = "功能"
                    };
                    dbcontext.TagGroups.Add(tg);

                    var tag1 = new Tag()
                    {
                        Name = "食品",
                        Group = tg
                    };
                    dbcontext.Tags.Add(tag1);

                    var tag2 = new Tag()
                    {
                        Name = "书籍",
                        Group = tg
                    };
                    dbcontext.Tags.Add(tag2);

                    var tag3 = new Tag()
                    {
                        Name = "酒水",
                        Group = tg
                    };
                    dbcontext.Tags.Add(tag3);

                    var product = new Product()
                    {
                        Name = "乐事薯片100g(清新黄瓜)",
                        ScanCode = "111"
                    };
                    dbcontext.Products.Add(product);

                    var good = new Goods()
                    {
                        GoodsCode = "111",
                        InboundDate = DateTime.Now,
                        Product = product,
                        State = GoodsState.Inbounding
                    };
                    dbcontext.Goods.Add(good);

                    dbcontext.SaveChanges();
                }
                catch
                {
                    // do nothing
                }
            }
            using (var dbcontext = new WarehouseContext())
            {
                var item = dbcontext.Goods.First();
            }
        }