public bool SaveSupplier(CommContracts.Supplier supplier) { using (DAL.HisContext ctx = new DAL.HisContext()) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <CommContracts.Supplier, DAL.Supplier>(); }); var mapper = config.CreateMapper(); DAL.Supplier temp = new DAL.Supplier(); temp = mapper.Map <DAL.Supplier>(supplier); ctx.Suppliers.Add(temp); try { ctx.SaveChanges(); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(false); } } return(true); }
public bool UpdateSupplier(CommContracts.Supplier supplier) { using (DAL.HisContext ctx = new DAL.HisContext()) { var temp = ctx.Suppliers.FirstOrDefault(m => m.ID == supplier.ID); if (temp != null) { temp.Name = supplier.Name; temp.Contents = supplier.Contents; temp.Tel = supplier.Tel; temp.Address = supplier.Address; } else { return(false); } try { ctx.SaveChanges(); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(false); } } return(true); }
public List <CommContracts.Supplier> GetAllSuppliers(string strFindName) { List <CommContracts.Supplier> list = new List <CommContracts.Supplier>(); using (DAL.HisContext ctx = new DAL.HisContext()) { var query = from a in ctx.Suppliers where a.Name.StartsWith(strFindName) || a.Abbr1.StartsWith(strFindName) || a.Abbr2.StartsWith(strFindName) || a.Abbr3.StartsWith(strFindName) select a; foreach (DAL.Supplier ass in query) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <DAL.Supplier, CommContracts.Supplier>(); }); var mapper = config.CreateMapper(); CommContracts.Supplier temp = mapper.Map <CommContracts.Supplier>(ass); list.Add(temp); } } return(list); }
public EditSupplierView(CommContracts.Supplier supplier = null) { InitializeComponent(); bIsEdit = false; if (supplier != null) { this.Supplier = supplier; this.NameEdit.Text = supplier.Name; this.ContentsEdit.Text = supplier.Contents; this.TelEdit.Text = supplier.Tel; this.AddressEdit.Text = supplier.Address; bIsEdit = true; } }
private void SaveBtn_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(this.NameEdit.Text.Trim())) { return; } if (bIsEdit) { Supplier.Name = this.NameEdit.Text.Trim(); Supplier.Contents = this.ContentsEdit.Text.Trim(); Supplier.Tel = this.TelEdit.Text.Trim(); Supplier.Address = this.AddressEdit.Text.Trim(); CommClient.Supplier myd = new CommClient.Supplier(); if (myd.UpdateSupplier(Supplier)) { (this.Parent as Window).DialogResult = true; (this.Parent as Window).Close(); } } else { CommContracts.Supplier supplier = new CommContracts.Supplier(); supplier.Name = this.NameEdit.Text.Trim(); supplier.Contents = this.ContentsEdit.Text.Trim(); supplier.Tel = this.TelEdit.Text.Trim(); supplier.Address = this.AddressEdit.Text.Trim(); CommClient.Supplier myd = new CommClient.Supplier(); if (myd.SaveSupplier(supplier)) { (this.Parent as Window).DialogResult = true; (this.Parent as Window).Close(); } } }