protected void MagicItemCommand(object sender, MagicItemEventArgs e) { if (e.CommandName == "Delete") { bool deleted = false; using (ISession session = new Session()) { session.BeginTransaction(); try { foreach (RepeaterItem item in this.rptLogistics.Items) { HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox; if (chk != null && chk.Checked && Cast.Int(chk.Value) > 0) { Magic.Basis.Logistics logistics = Magic.Basis.Logistics.Retrieve(session, Cast.Int(chk.Value)); if (logistics != null) { //逻辑删除,仅将状态update成UserStatus.Deleted logistics.Status = LogisticsStatus.Delete; logistics.Update(session, "Status"); deleted = true; } } } session.Commit(); if (deleted) { RestoreLastQuery(session); WebUtil.ShowMsg(this, "选择的配送商已经被删除", "操作成功"); } } catch (Exception ex) { session.Rollback(); WebUtil.ShowError(this, ex); } } } }
public void LogisReturn(ISession session, string locationCode, string snNumber, int reasonId, bool isMalicious, bool hasTransported, string note, int createUser) { if (string.IsNullOrEmpty(snNumber) || snNumber.Trim().Length <= 0) { throw new Exception("必须填写发货单号码"); } CRMSN sn = CRMSN.Retrieve(session, snNumber.Trim()); if (sn == null) { throw new Exception("发货单" + snNumber + "不存在"); } if (sn.Status == CRMSNStatus.Return) { throw new Exception("发货单" + sn.OrderNumber + "已经退货"); } if (sn.Status == CRMSNStatus.PartExchange) { throw new Exception("发货单" + sn.OrderNumber + "已经换货"); } if (sn.Status != CRMSNStatus.Interchanged) { throw new Exception("发货单" + snNumber + "未完成,无法退货"); } if (!string.IsNullOrEmpty(this.OrderNumber) && this.OrderNumber.Trim().Length > 0 && !string.IsNullOrEmpty(this.RefOrderNumber) && this.RefOrderNumber.Trim().Length > 0 && this.RefOrderNumber != snNumber) { //发货单号码改变,检查是否已经有明细存在,如果已经有明细了则不允许删除 if (session.CreateEntityQuery <ReturnLine>().Where(Exp.Eq("OrderNumber", this.OrderNumber)).Count() > 0) { throw new Exception("退货单" + this.OrderNumber + "已经存在退货明细,无法再改变发货单号码"); } } this.RefOrderNumber = sn.OrderNumber; this.RefOrderID = sn.ID; this.OrginalOrderNumber = sn.SaleOrderNumber; this.MemberID = sn.MemberID; if (sn.MemberID > 0) { Magic.Basis.Member member = Magic.Basis.Member.Retrieve(session, sn.MemberID); if (member != null) { this.MemberName = member.Name; } } this.LogisticsID = sn.LogisticsID; if (this.LogisticsID > 0) { Magic.Basis.Logistics logis = Magic.Basis.Logistics.Retrieve(session, this.LogisticsID); this.LogisticsName = logis.ShortName; } this.LocationCode = locationCode; this.IsMalicious = isMalicious; this.HasTransported = hasTransported; this.Note = note; this.ReasonID = reasonId; if (reasonId > 0) { Magic.Basis.ReturnReason reason = Magic.Basis.ReturnReason.Retrieve(session, reasonId); if (reason != null) { this.ReasonText = reason.ReasonText; } } this.OrderTypeCode = ORDER_TYPE_LOGISTICS_RTN; this.CreateUser = createUser; this.IsAutoMatch = true; }