public override void SendEmailAsync <T> (Operation <T> operation, string recipients, string body) { EmailServer emailServer = new EmailServer(); emailServer.SendCompleted += (sender, e) => { switch (e.EmailResult) { case EmailResult.NoSmtpServer: BusinessDomain.OnPriceRuleMessage(new PriceRuleMessageEventArgs(Translator.GetString( "The price rule could not send an e-mail because you haven't " + "specified an SMTP server in the application settings."), ErrorSeverity.Error)); break; case EmailResult.NoSender: BusinessDomain.OnPriceRuleMessage(new PriceRuleMessageEventArgs(Translator.GetString( "The price rule could not send an e-mail because you haven't " + "specified an email sender in the application settings."), ErrorSeverity.Error)); break; case EmailResult.InvalidPort: BusinessDomain.OnPriceRuleMessage(new PriceRuleMessageEventArgs(Translator.GetString( "The price rule could not send an e-mail because the port you " + "specified for the SMTP server is invalid."), ErrorSeverity.Error)); break; case EmailResult.SmtpError: BusinessDomain.OnPriceRuleMessage(new PriceRuleMessageEventArgs(Translator.GetString( "The price rule could not send an e-mail because of an error in the communication " + "with the SMTP server. Please check the settings of your SMTP server."), ErrorSeverity.Error)); break; } }; emailServer.SendEmail(recipients, null, body, true); }
public static T CreateImportedObject <T> (PropertyMap propertyMap, params string [] values) { T ret = (T)DataProvider.CreateObject(typeof(T)); for (int i = 0; i < values.Length; i++) { List <PropertyInfo> properties; if (!propertyMap.TryGetValue(i, out properties)) { continue; } string value = values [i]; foreach (PropertyInfo info in properties) { info.SetValue(ret, BusinessDomain.GetObjectValue(info.PropertyType, value), null); } } return(ret); }
public static string DataTypeToString(object obj, DataType type) { if (obj == null) { throw new ArgumentNullException("obj"); } switch (type) { case DataType.Date: case DataType.DateTime: if (!(obj is DateTime)) { throw new ArgumentException("The passed object is not System.DateTime", "obj"); } DateTime date = (DateTime)obj; return(type == DataType.DateTime ? BusinessDomain.GetFormattedDateTime(date) : BusinessDomain.GetFormattedDate(date)); case DataType.Quantity: if (obj is double) { return(Quantity.ToString((double)obj)); } throw new ArgumentException("The passed object is not System.Double", "obj"); case DataType.CurrencyIn: if (obj is double) { return(Currency.ToString((double)obj, PriceType.Purchase)); } throw new ArgumentException("The passed object is not System.Double", "obj"); case DataType.CurrencyOut: if (obj is double) { return(Currency.ToString((double)obj)); } throw new ArgumentException("The passed object is not System.Double", "obj"); case DataType.Currency: if (obj is double) { return(Currency.ToString((double)obj, PriceType.Unknown)); } throw new ArgumentException("The passed object is not System.Double", "obj"); case DataType.Id: if ((obj is long) || (obj is int)) { return(obj.ToString()); } throw new ArgumentException("The passed object is not System.Long or System.Int", "obj"); case DataType.DocumentNumber: TypeCode typeCode = Type.GetTypeCode(obj.GetType()); if (TypeCode.Char <= typeCode && typeCode <= TypeCode.UInt64) { return(Operation.GetFormattedOperationNumber(Convert.ToInt64(obj))); } string value = obj as string; if (value != null) { return(value); } throw new ArgumentException("The passed object is not a number or System.String", "obj"); case DataType.Percent: if (obj is double) { return(Percent.ToString((double)obj)); } throw new ArgumentException("The passed object is not System.Double", "obj"); default: return(obj.ToString()); } }