public static int 批量生成费用(IRepository rep, 车辆产值 票, IEnumerable 箱, string 费用项编号, 收付标志? 收付标志) { int cnt = 0; // 需按照委托人合同和付款合同生成相应费用和费用理论值 // 如果总体来生成,则按照: // 如果费用已经打了完全标志,则不生成。如果相应理论值已经生成过,也不生成。 // 如果单个费用项来生成,则不管理论值是否已经生成过 // Todo: 理论值可能显示生成票的,后来信息完全了再生成箱的,此时要删除票的 //using (IRepository rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository(票.GetType())) { try { rep.BeginTransaction(); IList<业务费用理论值> llzs = (rep as Feng.NH.INHibernateRepository).List<业务费用理论值>(NHibernate.Criterion.DetachedCriteria.For<业务费用理论值>() .Add(NHibernate.Criterion.Expression.Eq("费用实体.ID", 票.ID))); rep.Initialize(票.费用, 票); process_fy_generate.批量生成费用(rep, 票, 箱, 费用项编号, 收付标志, llzs); //// 有几项(发票税,贴息费)要看收款费用 // 不行,会多生成 //批量生成费用付款(rep, 费用实体类型, 票, 箱, 费用项编号, 收付标志, llzs); rep.CommitTransaction(); } catch (Exception ex) { rep.RollbackTransaction(); ServiceProvider.GetService<IExceptionProcess>().ProcessWithNotify(ex); } } return cnt; }
private void SaveFiles(IRepository rep, KeyValuePair<string, IList<string>> fileList) { foreach (string file in fileList.Value) { try { rep.BeginTransaction(); if (File.Exists(file)) { byte[] bytes = ReadFile(file); if (bytes == null || bytes.Length == 0) { Console.WriteLine("ForWatcher Error:<" + fileList.Key + ">" + Environment.NewLine + "Nor found the file or fileStream length is 0 \"" + file + "\""); continue; } FileInfo fileInfo = new FileInfo(file); AttachmentInfo newAtt = new AttachmentInfo(); newAtt.EntityName = m_EntityName; newAtt.EntityId = fileList.Key; newAtt.FileName = fileInfo.Name; newAtt.Data = bytes; newAtt.Description = "附件"; newAtt.Created = fileInfo.CreationTime; newAtt.CreatedBy = "服务"; newAtt.Updated = fileInfo.LastWriteTime; rep.Save(newAtt); } rep.CommitTransaction(); } catch (Exception ex) { rep.RollbackTransaction(); Console.WriteLine("ForWatcher Error:<" + fileList.Key + ">" + Environment.NewLine + ex.Message); System.Windows.Forms.MessageBox.Show("<" + fileList.Key + ">" + Environment.NewLine + ex.Message, "ForWatcher Error"); continue; } } }
/// <summary> /// default constructor of the object /// </summary> public FacebookStreamReader( Action<long, StreamUpdateStatus> statusNotificationHandler, Action<long, int, int> likesRetrivalNotificationHandler, long uniqueStatusIndentifier, string fbFilePath, ILogger logger, FacebookClient fbApp, IRepository repository) { Logger = logger; Logger.Info("Started"); UniqueStatusIndentifier = uniqueStatusIndentifier; StatusNotificationHandler = statusNotificationHandler; LikesRetrivalNotificationHandler = likesRetrivalNotificationHandler; Status = new List<StreamUpdateStatus>(); FbStreamUpdated += FacebookStreamReaderFbStreamUpdated; /* settings of the application */ SavedFbInfoPath = fbFilePath; /* facebook application interface */ FbApp = fbApp; Repository = repository; Repository.BeginTransaction(); }
public virtual void UpdateReferencesTo(ContentItem targetItem, string oldUrl = null, bool isRenamingDirectory = false) { logger.InfoFormat("Updating references to {0} from old url '{1}'. directory = {2}", targetItem, oldUrl, isRenamingDirectory); var newUrl = targetItem.Url; using (var tx = repository.BeginTransaction()) { var itemsWithReferencesToTarget = oldUrl == null? FindReferrers(targetItem).ToList() : FindReferrers(oldUrl).ToList(); foreach (var referrer in itemsWithReferencesToTarget) { var trackerCollecetion = referrer.GetDetailCollection(Tracker.LinkDetailName, false); if (trackerCollecetion == null || trackerCollecetion.Details.Count == 0) { continue; } var trackerDetails = trackerCollecetion.Details .Where(d => d.IntValue.HasValue) .OrderBy(d => d.IntValue.Value) .ToList(); logger.DebugFormat("Updating links on {0}. Details = {1}", referrer, trackerDetails.Count); for (int i = 0; i < trackerDetails.Count; i++) { var detail = trackerDetails[i]; var name = detail.Meta; if (name == null || detail.StringValue == null) { // don't update legacy links continue; } if (!detail.LinkedItem.HasValue && targetItem.ID != 0) { logger.DebugFormat("Skipping due to null linked item and nonempty target {0}", targetItem); continue; } else if (detail.LinkedItem.HasValue && detail.LinkedItem.ID != targetItem.ID) { // don't update other links logger.DebugFormat("Skipping due to other linked item: {0} != {1}", detail.LinkedItem, targetItem); continue; } // case 1: directory rename // oldUrl: /upl/x/y/ // StringVal: /upl/x/y/hej.jpg // item.Url /upl/x/y2/ else if (oldUrl != null && !detail.StringValue.StartsWith(oldUrl, StringComparison.InvariantCultureIgnoreCase)) { // don't update other images logger.DebugFormat("Skipping due to other url: '{0}' != '{1}'", detail.StringValue, oldUrl); continue; } if (isRenamingDirectory) { newUrl = targetItem.Url + detail.StringValue.Substring(oldUrl.Length); } Update(referrer, detail, name, newUrl, trackerDetails.Skip(i + 1).ToList()); } repository.SaveOrUpdate(referrer); } tx.Commit(); } }
private static bool InternalExecuteWindowMenu2(IControlManager cm, WindowMenuInfo info, Form parentForm) { object entity = cm.DisplayManager.CurrentItem; int pos = cm.DisplayManager.Position; //ArchiveOperationForm opForm = masterForm as ArchiveOperationForm; switch (info.Type) { case WindowMenuType.Add: { ArchiveOperationForm.DoAddS(cm); } break; case WindowMenuType.Edit: { ArchiveOperationForm.DoEditS(cm, (parentForm as IGridNamesContainer).GridNames[0]); } break; case WindowMenuType.Delete: { ArchiveOperationForm.DoDeleteS(cm, (parentForm as IGridNamesContainer).GridNames[0]); } break; case WindowMenuType.Confirm: { parentForm.ValidateChildren(); ArchiveDetailForm.DoSaveS(cm); } break; case WindowMenuType.Cancel: { ArchiveDetailForm.DoCancelS(cm); } break; case WindowMenuType.Submit: { if (entity == null) { MessageForm.ShowError("请选择要提交的项!"); return(true); } if (!MessageForm.ShowYesNo("是否确认提交?")) { return(true); } ISubmittedEntity se = entity as ISubmittedEntity; if (se == null) { throw new ArgumentException("Submit Entity should be ISubmittedEntity!"); } if (string.IsNullOrEmpty(info.ExecuteParam)) { cm.EditCurrent(); se.Submitted = true; cm.EndEdit(); } else { ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao; if (dao == null) { throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { se.Submitted = true; rep.BeginTransaction(); dao.Submit(rep, entity); rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { se.Submitted = false; rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } } break; case WindowMenuType.Unsubmit: { if (entity == null) { MessageForm.ShowError("请选择要撤销提交的项!"); return(true); } if (!MessageForm.ShowYesNo("是否确认撤销提交?", "确认", true)) { return(true); } ISubmittedEntity se = entity as ISubmittedEntity; if (se == null) { throw new ArgumentException("Submit Entity should be ISubmittedEntity!"); } if (string.IsNullOrEmpty(info.ExecuteParam)) { cm.EditCurrent(); se.Submitted = false; cm.EndEdit(); } else { ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao; if (dao == null) { throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { se.Submitted = false; rep.BeginTransaction(); dao.Unsubmit(rep, entity); rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { se.Submitted = true; rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } } break; case WindowMenuType.SubmitMulti: { if (cm.DisplayManager.Count == 0) { MessageForm.ShowError("请选择要提交的项!"); return(true); } if (!MessageForm.ShowYesNo("是否确认提交(当前全部)?")) { return(true); } ISubmittedEntity se = entity as ISubmittedEntity; if (se == null) { throw new ArgumentException("Submit Entity should be ISubmittedEntity!"); } if (string.IsNullOrEmpty(info.ExecuteParam)) { IBatchDao batchDao = cm.Dao as IBatchDao; if (batchDao != null) { batchDao.SuspendOperation(); } for (int i = 0; i < cm.DisplayManager.Count; ++i) { cm.DisplayManager.Position = i; cm.EditCurrent(); (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true; cm.EndEdit(); } if (batchDao != null) { batchDao.ResumeOperation(); } } else { ISubmittedEntityDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ISubmittedEntityDao; if (dao == null) { throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ISubmittedEntityDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { rep.BeginTransaction(); for (int i = 0; i < cm.DisplayManager.Count; ++i) { (cm.DisplayManager.Items[i] as ISubmittedEntity).Submitted = true; dao.Submit(rep, cm.DisplayManager.Items[i]); } rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { se.Submitted = false; rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } } break; case WindowMenuType.Cancellate: { if (entity == null) { MessageForm.ShowError("请选择要作废的项!"); return(true); } if (!MessageForm.ShowYesNo("是否确认作废?", "确认", true)) { return(true); } ICancellateDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(info.ExecuteParam) as ICancellateDao; if (dao == null) { throw new ArgumentException("Submit windowMenuType's ExecuteParam should be ICancellateDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { rep.BeginTransaction(); dao.Cancellate(rep, entity); rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } break; case WindowMenuType.DaoProcess: { if (entity == null) { MessageForm.ShowError("请选择要操作的项!"); return(true); } if (!MessageForm.ShowYesNo("是否要执行" + info.Text + "?")) { return(true); } string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length != 2) { throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam should be IDao;MethodName!"); } IRepositoryDao dao = Feng.Utils.ReflectionHelper.CreateInstanceFromName(ss[0].Trim()) as IRepositoryDao; if (dao == null) { throw new ArgumentException("DaoProcess windowMenuType's ExecuteParam's first part should be IDao!"); } using (IRepository rep = dao.GenerateRepository()) { try { rep.BeginTransaction(); Feng.Utils.ReflectionHelper.RunInstanceMethod(ss[0].Trim(), ss[1].Trim(), dao, new object[] { rep, entity }); rep.CommitTransaction(); cm.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, pos)); } catch (Exception ex) { rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } } break; case WindowMenuType.Select: { string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length == 0) { throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name); } ArchiveCheckForm form = ServiceProvider.GetService <IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveCheckForm; if (ss.Length > 1) { string exp = ss[1]; exp = EntityHelper.ReplaceEntity(exp, new EntityHelper.GetReplaceValue(delegate(string paramName) { Tuple <string, object> t = EventProcessUtils.GetDataControlValue(paramName, cm.DisplayManager); if (t.Item2 == null) { throw new InvalidUserOperationException(string.Format("请先填写{0}!", paramName)); } cm.DisplayManager.DataControls[t.Item1].ReadOnly = true; // save controlValue to entity because readonly will not save EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, t.Item1, t.Item2); return(t.Item2); })); if (string.IsNullOrEmpty(form.DisplayManager.SearchManager.AdditionalSearchExpression)) { form.DisplayManager.SearchManager.AdditionalSearchExpression = exp; } else { form.DisplayManager.SearchManager.AdditionalSearchExpression = "(" + form.DisplayManager.SearchManager.AdditionalSearchExpression + ") and " + exp; } } int detailGridIdx = 0; if (ss.Length > 2) { detailGridIdx = Feng.Utils.ConvertHelper.ToInt(ss[2]).Value; } if (form.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK) { IControlManager detailCm = (((IArchiveDetailFormWithDetailGrids)(parentForm as IArchiveMasterForm).ArchiveDetailForm).DetailGrids[detailGridIdx] as IArchiveGrid).ControlManager; var nowList = detailCm.DisplayManager.Items; foreach (object i in form.SelectedEntites) { if (nowList.Contains(i)) { continue; } detailCm.AddNew(); detailCm.DisplayManager.Items[detailCm.DisplayManager.Position] = i; detailCm.EndEdit(); } } form.Dispose(); } break; case WindowMenuType.Input: throw new NotSupportedException("Not supported now!"); case WindowMenuType.ManyToOneWindow: { if (cm.DisplayManager.CurrentItem == null) { MessageForm.ShowInfo("无当前项,不能操作!"); return(true); } string[] ss = info.ExecuteParam.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (ss.Length < 2) { throw new ArgumentException("WindowMenu's ExecuteParam is Invalid of WindowMenu " + info.Name); } ArchiveDetailForm selectForm = ServiceProvider.GetService <IWindowFactory>().CreateWindow(ADInfoBll.Instance.GetWindowInfo(ss[0])) as ArchiveDetailForm; string propertyName = ss[1]; object masterEntity = EntityScript.GetPropertyValue(cm.DisplayManager.CurrentItem, propertyName); if (masterEntity == null) { ArchiveOperationForm.DoAddS(selectForm.ControlManager); selectForm.UpdateContent(); if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK) { cm.EditCurrent(); EntityScript.SetPropertyValue(cm.DisplayManager.CurrentItem, propertyName, selectForm.DisplayManager.CurrentItem); cm.EndEdit(); cm.OnCurrentItemChanged(); } } else { selectForm.ControlManager.AddNew(); selectForm.DisplayManager.Items[selectForm.DisplayManager.Position] = masterEntity; selectForm.ControlManager.EndEdit(false); ArchiveOperationForm.DoEditS(selectForm.ControlManager, selectForm.GridName); selectForm.UpdateContent(); if (selectForm.ShowDialog(parentForm) == System.Windows.Forms.DialogResult.OK) { ((parentForm as IArchiveMasterForm).MasterGrid as IBoundGrid).ReloadData(); } } selectForm.Dispose(); } break; default: return(false); } return(true); }
public void BeginTransaction() { _repository.BeginTransaction(); }
public async Task <Result <Order> > CreateOrder(long cartId, string paymentMethod, decimal paymentFeeAmount, string shippingMethodName, Address billingAddress, Address shippingAddress, OrderStatus orderStatus = OrderStatus.New) { var cart = _cartRepository .Query() .Include(c => c.Items).ThenInclude(x => x.Product) .Where(x => x.Id == cartId).FirstOrDefault(); if (cart == null) { return(Result.Fail <Order>($"Cart id {cartId} cannot be found")); } var checkingDiscountResult = await CheckForDiscountIfAny(cart); if (!checkingDiscountResult.Succeeded) { return(Result.Fail <Order>(checkingDiscountResult.ErrorMessage)); } var validateShippingMethodResult = await ValidateShippingMethod(shippingMethodName, shippingAddress, cart); if (!validateShippingMethodResult.Success) { return(Result.Fail <Order>(validateShippingMethodResult.Error)); } var shippingMethod = validateShippingMethodResult.Value; var orderBillingAddress = new OrderAddress() { AddressLine1 = billingAddress.AddressLine1, AddressLine2 = billingAddress.AddressLine2, ContactName = billingAddress.ContactName, CountryId = billingAddress.CountryId, StateOrProvinceId = billingAddress.StateOrProvinceId, DistrictId = billingAddress.DistrictId, City = billingAddress.City, ZipCode = billingAddress.ZipCode, Phone = billingAddress.Phone }; var orderShippingAddress = new OrderAddress() { AddressLine1 = shippingAddress.AddressLine1, AddressLine2 = shippingAddress.AddressLine2, ContactName = shippingAddress.ContactName, CountryId = shippingAddress.CountryId, StateOrProvinceId = shippingAddress.StateOrProvinceId, DistrictId = shippingAddress.DistrictId, City = shippingAddress.City, ZipCode = shippingAddress.ZipCode, Phone = shippingAddress.Phone }; var order = new Order { CustomerId = cart.CustomerId, CreatedOn = DateTimeOffset.Now, CreatedById = cart.CreatedById, LatestUpdatedOn = DateTimeOffset.Now, LatestUpdatedById = cart.CreatedById, BillingAddress = orderBillingAddress, ShippingAddress = orderShippingAddress, PaymentMethod = paymentMethod, PaymentFeeAmount = paymentFeeAmount }; foreach (var cartItem in cart.Items) { if (cartItem.Product.StockTrackingIsEnabled && cartItem.Product.StockQuantity < cartItem.Quantity) { return(Result.Fail <Order>($"There are only {cartItem.Product.StockQuantity} items available for {cartItem.Product.Name}")); } var taxPercent = await _taxService.GetTaxPercent(cartItem.Product.TaxClassId, shippingAddress.CountryId, shippingAddress.StateOrProvinceId, shippingAddress.ZipCode); var productPrice = cartItem.Product.Price; if (cart.IsProductPriceIncludeTax) { productPrice = productPrice / (1 + (taxPercent / 100)); } var orderItem = new OrderItem { Product = cartItem.Product, ProductPrice = productPrice, Quantity = cartItem.Quantity, TaxPercent = taxPercent, TaxAmount = cartItem.Quantity * (productPrice * taxPercent / 100) }; var discountedItem = checkingDiscountResult.DiscountedProducts.FirstOrDefault(x => x.Id == cartItem.ProductId); if (discountedItem != null) { orderItem.DiscountAmount = discountedItem.DiscountAmount; } order.AddOrderItem(orderItem); if (cartItem.Product.StockTrackingIsEnabled) { cartItem.Product.StockQuantity = cartItem.Product.StockQuantity - cartItem.Quantity; } } order.OrderStatus = orderStatus; order.OrderNote = cart.OrderNote; order.CouponCode = checkingDiscountResult.CouponCode; order.CouponRuleName = cart.CouponRuleName; order.DiscountAmount = checkingDiscountResult.DiscountAmount; order.ShippingFeeAmount = shippingMethod.Price; order.ShippingMethod = shippingMethod.Name; order.TaxAmount = order.OrderItems.Sum(x => x.TaxAmount); order.SubTotal = order.OrderItems.Sum(x => x.ProductPrice * x.Quantity); order.SubTotalWithDiscount = order.SubTotal - checkingDiscountResult.DiscountAmount; order.OrderTotal = order.SubTotal + order.TaxAmount + order.ShippingFeeAmount + order.PaymentFeeAmount - order.DiscountAmount; _orderRepository.Add(order); cart.IsActive = false; var vendorIds = cart.Items.Where(x => x.Product.VendorId.HasValue).Select(x => x.Product.VendorId.Value).Distinct(); if (vendorIds.Any()) { order.IsMasterOrder = true; } IList <Order> subOrders = new List <Order>(); foreach (var vendorId in vendorIds) { var subOrder = new Order { CustomerId = cart.CustomerId, CreatedOn = DateTimeOffset.Now, CreatedById = cart.CreatedById, LatestUpdatedOn = DateTimeOffset.Now, LatestUpdatedById = cart.CreatedById, BillingAddress = orderBillingAddress, ShippingAddress = orderShippingAddress, VendorId = vendorId, Parent = order }; foreach (var cartItem in cart.Items.Where(x => x.Product.VendorId == vendorId)) { var taxPercent = await _taxService.GetTaxPercent(cartItem.Product.TaxClassId, shippingAddress.CountryId, shippingAddress.StateOrProvinceId, shippingAddress.ZipCode); var productPrice = cartItem.Product.Price; if (cart.IsProductPriceIncludeTax) { productPrice = productPrice / (1 + (taxPercent / 100)); } var orderItem = new OrderItem { Product = cartItem.Product, ProductPrice = productPrice, Quantity = cartItem.Quantity, TaxPercent = taxPercent, TaxAmount = cartItem.Quantity * (productPrice * taxPercent / 100) }; if (cart.IsProductPriceIncludeTax) { orderItem.ProductPrice = orderItem.ProductPrice - orderItem.TaxAmount; } subOrder.AddOrderItem(orderItem); } subOrder.SubTotal = subOrder.OrderItems.Sum(x => x.ProductPrice * x.Quantity); subOrder.TaxAmount = subOrder.OrderItems.Sum(x => x.TaxAmount); subOrder.OrderTotal = subOrder.SubTotal + subOrder.TaxAmount + subOrder.ShippingFeeAmount - subOrder.DiscountAmount; _orderRepository.Add(subOrder); subOrders.Add(subOrder); } using (var transaction = _orderRepository.BeginTransaction()) { _orderRepository.SaveChanges(); await PublishOrderCreatedEvent(order); foreach (var subOrder in subOrders) { await PublishOrderCreatedEvent(subOrder); } _couponService.AddCouponUsage(cart.CustomerId, order.Id, checkingDiscountResult); _orderRepository.SaveChanges(); transaction.Commit(); } return(Result.Ok(order)); }
public static void EditLlz(ArchiveSeeForm masterForm) { Xceed.Grid.Row row = (masterForm.ArchiveDetailForm as IArchiveDetailFormWithDetailGrids).DetailGrids[0].CurrentRow; if (row == null) { throw new InvalidUserOperationException("请选择要编辑理论值的合同费用项!"); } 合同费用项 htfyx = (row as Xceed.Grid.DataRow).Tag as 合同费用项; using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <费用理论值信息>()) { rep.Initialize(htfyx.费用理论值, htfyx); } IList <string> llzs = new List <string>(); if (htfyx.费用理论值 != null) { foreach (费用理论值信息 i in htfyx.费用理论值) { llzs.Add(i.条件); llzs.Add(i.结果); } } FrmEditor form = new FrmEditor( new Dictionary <string, string> { { "委托人编号", "人员单位_委托人" }, { "船公司编号", "人员单位_船公司" }, { "箱型编号", "备案_箱型_全部" }, { "卸箱地编号", "人员单位_港区堆场" }, { "费用项编号", "费用项_全部" } }, llzs); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { IList <string> ret = form.GetResult(); using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <费用理论值信息>()) { try { rep.BeginTransaction(); foreach (费用理论值信息 i in htfyx.费用理论值) { rep.Delete(i); } htfyx.费用理论值.Clear(); for (int i = 0; i < ret.Count; i += 2) { 费用理论值信息 item = new 费用理论值信息(); item.合同费用项 = htfyx; item.结果 = ret[i + 1]; item.条件 = ret[i]; item.序号 = i / 2; (new HdBaseDao <费用理论值信息>()).Save(rep, item); htfyx.费用理论值.Add(item); } rep.CommitTransaction(); } catch (Exception ex) { rep.RollbackTransaction(); ServiceProvider.GetService <IExceptionProcess>().ProcessWithNotify(ex); } } } }
public async Task <Result> RegisterByPhone(RegisterByPhoneParam model) { var any = _userManager.Users.Any(c => c.PhoneNumber == model.Phone); if (any) { return(Result.Fail("此手机号已被注册")); } //5分钟内的验证码 //var sms = _smsSendRepository // .Query(c => c.PhoneNumber == model.Phone && c.IsSucceed && !c.IsUsed && c.TemplateType == SmsTemplateType.Captcha // && c.CreatedOn >= DateTime.Now.AddMinutes(-5)).OrderByDescending(c => c.CreatedOn).FirstOrDefault(); //if (sms == null) // return Result.Fail("验证码不存在或已失效,请重新获取验证码"); //if (sms.Value != model.Captcha) // return Result.Fail("验证码错误"); //5分钟内的验证码 var sms = await _accountService.ValidateGetLastSms(model?.Phone, model?.Captcha); var user = new User { UserName = Guid.NewGuid().ToString("N"), FullName = model.Phone, PhoneNumber = model.Phone, PhoneNumberConfirmed = true, IsActive = true, Culture = GlobalConfiguration.DefaultCulture }; if (!string.IsNullOrWhiteSpace(model.Email)) { var verify = RegexHelper.VerifyEmail(model.Email); if (!verify.Succeeded) { return(Result.Fail(verify.Message)); } var anyEmail = _userManager.Users.Any(c => c.Email == model.Email); if (anyEmail) { return(Result.Fail("此邮箱已被使用")); } user.Email = model.Email; user.EmailConfirmed = false; } var transaction = _userRepository.BeginTransaction(); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, RoleWithId.customer.ToString()); // 通过手机号注册成功的用户不自动登录,因为是JWT认证 // await _signInManager.SignInAsync(user, isPersistent: false); sms.IsUsed = true; sms.OutId = user.Id.ToString(); _smsSendRepository.SaveChanges(); transaction.Commit(); if (!string.IsNullOrEmpty(user.Email)) { // 发送邮箱激活码,激活则绑定邮箱 // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); await SendEmailConfirmation(user.Email, user.Id, code); } return(Result.Ok()); } return(Result.Fail(result.Errors?.Select(c => c.Description).FirstOrDefault())); }
/// <summary> /// 返回新任务号 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="是否动态">是否动态优化</param> /// <returns></returns> public 专家任务 生成专家任务(任务 x, 任务 y, bool 是否动态, 专家任务性质?xz, string bz, IRepository rep) { if ((x == null && y == null) || (x != null && y != null && x.专家任务 != null && y.专家任务 != null)) { throw new NullReferenceException("不能生成专家任务!"); } bool bx = false, by = false; try { rep.BeginTransaction(); 专家任务 zjrw = null; if (x != null && y != null) { // 动态 if (x.专家任务 != null || y.专家任务 != null) { zjrw = x.专家任务 != null ? x.专家任务 : y.专家任务; } else { zjrw = new 专家任务(); zjrw.任务 = new List <任务>(); zjrw.IsActive = true; zjrw.备注 = bz; zjrw.缓急程度 = Math.Max(x.缓急程度, y.缓急程度); } zjrw.任务性质 = Get专家任务性质(x, y, xz, 是否动态); if (zjrw.任务性质 == 专家任务性质.静态优化套箱 || zjrw.任务性质 == 专家任务性质.动态优化套箱) { if (x.任务性质 == 任务性质.出口装箱) { if (string.IsNullOrEmpty(x.箱号)) { x.箱号 = y.箱号; } } else if (y.任务性质 == 任务性质.出口装箱) { if (string.IsNullOrEmpty(y.箱号)) { y.箱号 = x.箱号; } } } switch (zjrw.任务性质) { case 专家任务性质.静态优化套箱: zjrw.新任务号 = "NT"; break; case 专家任务性质.动态优化套箱: zjrw.新任务号 = "MT"; break; case 专家任务性质.静态优化进口箱带货: zjrw.新任务号 = "NI"; break; case 专家任务性质.动态优化进口箱带货: zjrw.新任务号 = "MI"; break; case 专家任务性质.静态优化出口箱带货: zjrw.新任务号 = "NE"; break; case 专家任务性质.动态优化出口箱带货: zjrw.新任务号 = "ME"; break; case 专家任务性质.静态优化进出口对箱: zjrw.新任务号 = "NB"; break; case 专家任务性质.动态优化进出口对箱: zjrw.新任务号 = "MB"; break; case 专家任务性质.静态优化进口箱对箱: zjrw.新任务号 = "NS"; break; case 专家任务性质.动态优化进口箱对箱: zjrw.新任务号 = "MS"; break; case 专家任务性质.静态优化出口箱对箱: zjrw.新任务号 = "NA"; break; case 专家任务性质.动态优化出口箱对箱: zjrw.新任务号 = "MA"; break; } //zjrw.新任务号 += PrimaryMaxIdGenerator.GetIdYearMonth(); //zjrw.新任务号 = PrimaryMaxIdGenerator.GetMaxId("业务备案_专家任务", "新任务号", 12, zjrw.新任务号); string s = null; switch (zjrw.任务性质) { case 专家任务性质.静态优化套箱: case 专家任务性质.静态优化进口箱带货: case 专家任务性质.静态优化进口箱对箱: case 专家任务性质.静态优化进出口对箱: case 专家任务性质.动态优化套箱: case 专家任务性质.动态优化进口箱带货: case 专家任务性质.动态优化进口箱对箱: case 专家任务性质.动态优化进出口对箱: s = x.任务性质 == 任务性质.进口拆箱 ? x.任务号 : y.任务号; break; case 专家任务性质.静态优化出口箱带货: case 专家任务性质.静态优化出口箱对箱: case 专家任务性质.动态优化出口箱带货: case 专家任务性质.动态优化出口箱对箱: s = x.任务性质 == 任务性质.出口装箱 ? x.任务号 : y.任务号; break; default: throw new ArgumentException("不合理的专家任务性质!"); } zjrw.新任务号 += s.Substring(1); } else // 无优化专家任务 { 任务 rw = x != null ? x : y; if (rw.专家任务 == null) { zjrw = new 专家任务(); zjrw.任务 = new List <任务>(); zjrw.IsActive = true; zjrw.备注 = bz; zjrw.缓急程度 = rw.缓急程度; } else { zjrw = rw.专家任务; } zjrw.新任务号 = "O" + rw.任务号; zjrw.任务性质 = Get专家任务性质(rw); } base.SaveOrUpdate(rep, zjrw); if (x != null && x.专家任务 == null) { bx = true; x.专家任务 = zjrw; m_任务Dao.Update(rep, x); } if (y != null && y.专家任务 == null) { by = true; y.专家任务 = zjrw; m_任务Dao.Update(rep, y); } rep.CommitTransaction(); if (bx) { zjrw.任务.Add(x); } if (by) { zjrw.任务.Add(y); } return(zjrw); } catch (Exception ex) { rep.RollbackTransaction(); if (bx) { x.专家任务 = null; } if (by) { y.专家任务 = null; } ExceptionProcess.ProcessWithNotify(ex); return(null); } }
/// <summary> /// 已下达的专家任务,将无法删除和移出任务 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public bool 撤销专家任务(任务 x, 任务 y) { 专家任务 zjrw = null; if (x != null && y != null) { if (x.专家任务 == null || y.专家任务 == null) { return(true); } using (IRepository rep = this.GenerateRepository()) { rep.Attach(x); rep.Attach(y); zjrw = x.专家任务; if (zjrw == null) // 到这zjrw = null,可能因为多人操作,别人删除了专家任务 { return(true); } if (zjrw.达时间.HasValue) { return(false); } try { rep.BeginTransaction(); x.专家任务 = null; m_任务Dao.Update(rep, x); y.专家任务 = null; m_任务Dao.Update(rep, y); // 动态调度时,只撤销rw if (!zjrw.达时间.HasValue) { base.Delete(rep, zjrw); } rep.CommitTransaction(); } catch (Exception ex) { rep.RollbackTransaction(); x.专家任务 = zjrw; y.专家任务 = zjrw; ExceptionProcess.ProcessWithNotify(ex); return(false); } } return(true); } else { 任务 rw = x != null ? x : y; if (rw != null) { if (rw.专家任务 == null) { return(true); } using (IRepository rep = this.GenerateRepository()) { try { rep.Attach(rw); rep.BeginTransaction(); zjrw = rw.专家任务; if (zjrw == null) // 到这zjrw = null,可能因为多人操作,别人删除了专家任务 { return(true); } if (zjrw.达时间.HasValue) { return(false); } rw.专家任务 = null; m_任务Dao.Update(rep, rw); bool deleteZjrw = true; foreach (任务 rwItem in zjrw.任务) { if (rwItem.ID != rw.ID) { zjrw.任务性质 = Get专家任务性质(rwItem); base.Update(rep, zjrw); deleteZjrw = false; } } // 动态调度时,只撤销rw // 如果原有2个任务,会报约束异常 if (!zjrw.达时间.HasValue && deleteZjrw) { base.Delete(rep, zjrw); } rep.CommitTransaction(); } catch (Exception ex) { rep.RollbackTransaction(); rw.专家任务 = zjrw; ExceptionProcess.ProcessWithNotify(ex); return(false); } } } return(true); } }
/// <summary> /// 开始事物提交 /// </summary> public void BeginTransaction() { Service.BeginTransaction(); }