public Control CallAddProductControl(string productScanCode, WarehouseContext dbcontext, Action <Product> createCallback = null) { var formControl = FormControlHelper.CreateFormControl(); var product = new Product(); product.ScanCode = productScanCode; formControl.RenderForm(product, false); formControl.ConfirmButton.Content = "录入产品"; formControl.SubmitCallback = (d) => { try { dbcontext.Products.Add((Product)d); dbcontext.SaveChanges(); if (createCallback != null) { createCallback((Product)d); } } catch (Exception ex) { //TODO: handle exception formControl.SetErrorMsgManually("ScanCode", "此产品扫码已存在"); } }; return(formControl); }
public Control CallCreateUserControl(Action <User> createCallback = null) { var formControl = FormControlHelper.CreateFormControl(); formControl.RenderForm(new User(), false); formControl.ConfirmButton.Content = "创建用户"; formControl.SubmitCallback = (d) => { using (var dbcontext = new WarehouseContext()) { try { dbcontext.Users.Add((User)d); dbcontext.SaveChanges(); if (createCallback != null) { createCallback((User)d); } } catch (Exception ex) { //TODO: handle exception formControl.SetErrorMsgManually("Username", "此用户名已存在,请更换"); } } }; return(formControl); }
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); }
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; }
public Control CallViewUserControl(User user) { var formControl = FormControlHelper.CreateFormControl(); // remove password formControl.DetermineFieldCreationCallback = (cx, s) => { switch (cx.PropertyInfo.Name) { case "Username": return(true); case "Password": return(false); default: return(s); } }; formControl.RenderForm(user, true); return(formControl); }
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); }