public String Delete(int noteid, bool isdecrease) { String bErr = ""; CustomerEntity customer = null; if (isdecrease) { using (var repo = DMRepository.Get()) { DeliveryNote note = repo.Get <DeliveryNote>(p => p.noteid == noteid); if (note == null) { return("当前送货单不存在"); } Spec <CustomerEntity> where = new Spec <CustomerEntity>(); where.And(p => p.customer == note.customer); if (note.sdate.Year <= 1) { where.And(p => p.cyear == DateTime.Now.Year); } else { where.And(p => p.cyear == note.sdate.Year); } customer = repo.Get <CustomerEntity>(where.Exp); if (customer == null) { return("系统中没有此客户信息"); } if (customer.sequence != note.deliverid) { return("当前送货单已归档,不能删除"); } customer.sequence = customer.sequence - 1; } } using (var dmt = DMContext.GetTransaction()) { var trans = dmt.BeginTransaction(); if (customer != null & isdecrease) { DMContext.Update <CustomerEntity>(customer, p => p.cid == customer.cid, null, trans); } DMContext.Delete <DeliveryItem>(p => p.noteid == noteid, trans); DMContext.Delete <DeliveryNote>(p => p.noteid == noteid, trans); trans.Commit(); } return(bErr); }
public void Update(DeliveryNote note) { using (var dmt = DMContext.GetTransaction()) { int noteid = note.noteid; var trans = dmt.BeginTransaction(); DMContext.Delete <DeliveryItem>(p => p.noteid == noteid, trans); DMContext.Update <DeliveryNote>(note, p => p.noteid == noteid, null, trans); if (note.items != null) { foreach (DeliveryItem item in note.items) { item.noteid = note.noteid; DMContext.Insert(item, null, trans); } } trans.Commit(); } }
public bool Add(DeliveryNote note) { bool bRet = false; bool bNewCustomer = false;; int iDeliveryId; CustomerDAC dac = new CustomerDAC(); CustomerEntity objCustomer = dac.Select(note.customer); if (objCustomer == null) { bNewCustomer = true; objCustomer = new CustomerEntity(); objCustomer.customer = note.customer; objCustomer.cyear = DateTime.Now.Year; objCustomer.sequence = 1; iDeliveryId = 1; } else { bNewCustomer = false; if (objCustomer.cyear == DateTime.Now.Year) { objCustomer.sequence = objCustomer.sequence + 1; iDeliveryId = objCustomer.sequence; } else { objCustomer.cyear = DateTime.Now.Year; objCustomer.sequence = 1; iDeliveryId = 1; } } using (var dmt = DMContext.GetTransaction()) { var trans = dmt.BeginTransaction(); if (bNewCustomer) { DMContext.Insert(objCustomer, null, trans); } else { DMContext.Update <CustomerEntity>(objCustomer, p => p.cid == objCustomer.cid, null, trans); } note.deliverid = iDeliveryId; int noteId = DMContext.Insert(note, null, trans); if (noteId > 0) { if (note.items != null) { foreach (DeliveryItem item in note.items) { item.noteid = noteId; DMContext.Insert(item, null, trans); } } trans.Commit(); bRet = true; } } return(bRet); }