private void CreateTagGroup(TagGroup newtg)
        {
            var findtg = DBContext.TagGroups.FirstOrDefault((g) => g.Name == newtg.Name && g.State == StateCode.Active);

            if (findtg != null)
            {
                WindowMgr.SendNotification("标签组不能重名", NotificationLevel.Warning);
            }
            else
            {
                try
                {
                    DBContext.TagGroups.Add(newtg);
                    DBContext.SaveChanges();
                    WindowMgr.SendNotification("成功创建标签组", NotificationLevel.Information);
                    AddTagGroupNode(newtg);
                    ShowFormGrid(false);
                }
                catch (Exception ex)
                {
                    // TODO
                    WindowMgr.SendNotification("操作失败", NotificationLevel.Error);
                }
            }
        }
示例#2
0
        private void DeleteUser_Clicked(object sender, RoutedEventArgs e)
        {
            var data = ((Button)sender).DataContext as User;

            if (data != null)
            {
                var result = MessageBox.Show(
                    string.Format("你是否决定要删除用户'{0}'?", data.Name),
                    "操作警告",
                    MessageBoxButton.OKCancel,
                    MessageBoxImage.Warning);
                if (result == MessageBoxResult.OK)
                {
                    try
                    {
                        using (var dbcontext = new WarehouseContext())
                        {
                            var deluser = dbcontext.Users.Find(((User)data).UserId);
                            dbcontext.Users.Remove(deluser);
                            dbcontext.SaveChanges();
                            edit_br.Child = null;
                            ReloadUserGrid();
                        }
                    }
                    catch (Exception ex)
                    {
                        WindowMgr.SendNotification("删除操作失败。", NotificationLevel.Error);
                    }
                }
            }
        }
        public void CallCreateUserTabPage()
        {
            var tab  = WindowMgr.CreateTabPage("创建新用户", "创建新用户", false);
            var form = CallCreateUserControl((u) =>
            {
                WindowMgr.SendNotification("用户创建成功", NotificationLevel.Information);
                WindowMgr.CloseTabPage(tab);
            });

            tab.Content = form;
        }
        public void CallWarehouseInboundtPage()
        {
            WarehouseContext dbcontext;
            var tab         = WindowMgr.CreateTabPageWithDBContext("入库单", "入库单", false, out dbcontext);
            var formControl = FormControlHelper.CreateFormControl();

            formControl.CreateControlCallback = (cx, ctl) =>
            {
                if (cx.ControlType == ControlType.Label &&
                    cx.PropertyInfo.Name == "InboundGoods")
                {
                    ctl.VerticalAlignment = VerticalAlignment.Top;
                    return(ctl);
                }
                if (cx.ControlType == ControlType.Editable ||
                    cx.ControlType == ControlType.Readonly)
                {
                    switch (cx.PropertyInfo.Name)
                    {
                    case "Operator":
                        return(RenderSelectUserControl(cx, dbcontext));

                    case "InboundGoods":
                        return(new GoodsList(dbcontext));
                    }
                }
                return(ctl);
            };

            //form submit callback
            formControl.SubmitCallback = d =>
            {
                try
                {
                    dbcontext.WarehouseInbounds.Add((WarehouseInbound)d);
                    dbcontext.SaveChanges();
                    WindowMgr.SendNotification("入库成功", NotificationLevel.Information);
                    WindowMgr.CloseTabPage(tab);
                    dbcontext.Dispose();
                }
                catch (Exception ex)
                {
                    //TODO: handle exception
                    WindowMgr.SendNotification("入库操作失败", NotificationLevel.Error);
                }
            };

            var newinbound = new WarehouseInbound();

            newinbound.Name = string.Format("入库 - {0}", DateTime.Now);
            formControl.RenderForm(newinbound, false);
            formControl.ConfirmButton.Content = "入库";
            tab.Content = formControl;
        }
        private void deltag_click(object sender, RoutedEventArgs e)
        {
            var data = ((TreeViewItem)tagtree.SelectedItem).DataContext as Tag;

            data.State = StateCode.InActive;
            DBContext.SaveChanges();
            var tgnode = ((TreeViewItem)tagtree.SelectedItem).Parent as TreeViewItem;

            tgnode.Items.Remove(tagtree.SelectedItem);
            WindowMgr.SendNotification("标签已删除", NotificationLevel.Information);
        }
        bool CallResetPasswordPopup(User user)
        {
            var pwdwindow = new ResetPwdWindow(user);
            var result    = pwdwindow.ShowDialog();

            if (result.HasValue && result.Value)
            {
                WindowMgr.SendNotification("密码已重置", NotificationLevel.Information);
                return(true);
            }
            return(false);
        }
        public void CallAddProductPage()
        {
            var dbcontext = new WarehouseContext();
            var tab       = WindowMgr.CreateTabPage("添加产品信息", "添加产品信息", false);
            var form      = CallAddProductControl(null, dbcontext, (u) =>
            {
                WindowMgr.SendNotification("添加产品信息成功", NotificationLevel.Information);
                WindowMgr.CloseTabPage(tab);
                dbcontext.Dispose();
            });

            tab.Content = form;
        }
        private void deltaggroup_click(object sender, RoutedEventArgs e)
        {
            var data = ((TreeViewItem)tagtree.SelectedItem).DataContext as TagGroup;

            if (data.Tags.Count(t => t.State == StateCode.Active) > 0)
            {
                WindowMgr.SendNotification("标签组内还有标签,不能删除", NotificationLevel.Warning);
                return;
            }
            data.State = StateCode.InActive;
            DBContext.SaveChanges();
            tagtree.Items.Remove(tagtree.SelectedItem);
            WindowMgr.SendNotification("标签组已删除", NotificationLevel.Information);
        }
        private void UpdateTag(Tag updatetag)
        {
            var findtag = DBContext.Tags.FirstOrDefault((t) => t.Name == updatetag.Name && t.State == StateCode.Active);

            if (findtag != null)
            {
                WindowMgr.SendNotification("标签不能重名", NotificationLevel.Warning);
            }
            else
            {
                DBContext.SaveChanges();
                WindowMgr.SendNotification("成功更改标签", NotificationLevel.Information);
                ShowFormGrid(false);
            }
        }
        public Control CallUpdateUserControl(User user, Action <User> updateCallback = null)
        {
            var formControl = FormControlHelper.CreateFormControl();

            // remove password
            formControl.DetermineFieldCreationCallback = (cx, s) =>
            {
                switch (cx.PropertyInfo.Name)
                {
                case "Username":
                    return(true);

                default:
                    return(s);
                }
            };

            formControl.CreateControlCallback = (cx, c) =>
            {
                if (cx.ControlType == ControlType.Editable)
                {
                    if (cx.PropertyInfo.Name == "Password")
                    {
                        return(CreateResetPwdButton(user));
                    }
                    else if (cx.PropertyInfo.Name == "Username")
                    {
                        c.IsEnabled = false;
                    }
                }
                return(c);
            };

            formControl.SubmitCallback = (d) =>
            {
                using (var dbcontext = new WarehouseContext())
                {
                    try
                    {
                        var selectuser = d as User;
                        var updateuser = dbcontext.Users.Find(selectuser.UserId);
                        updateuser.Name                 = selectuser.Name;
                        updateuser.PhoneNumber          = selectuser.PhoneNumber;
                        updateuser.Memo                 = selectuser.Memo;
                        updateuser.IdentificationNumber = selectuser.IdentificationNumber;
                        updateuser.PermissionGroup      = selectuser.PermissionGroup;
                        updateuser.Department           = selectuser.Department;
                        dbcontext.SaveChanges();
                        WindowMgr.SendNotification("更新用户成功", NotificationLevel.Information);
                        if (updateCallback != null)
                        {
                            updateCallback(selectuser);
                        }
                    }
                    catch (Exception ex)
                    {
                        // TODO
                        WindowMgr.SendNotification("更新用户失败", NotificationLevel.Error);
                    }
                }
            };

            formControl.RenderForm(user, false);
            formControl.ConfirmButton.Content = "保存设置";

            return(formControl);
        }