protected static string GetFieldText(DataType fieldType, object value) { switch (fieldType) { case DataType.Date: return(BusinessDomain.GetFormattedDate((DateTime)value)); case DataType.DateTime: return(BusinessDomain.GetFormattedDateTime((DateTime)value)); case DataType.Quantity: return(Quantity.ToEditString((double)value)); case DataType.CurrencyIn: return(Currency.ToEditString((double)value, PriceType.Purchase)); case DataType.CurrencyOut: return(Currency.ToEditString((double)value)); case DataType.Currency: return(Currency.ToEditString((double)value, PriceType.Unknown)); case DataType.Percent: return(Percent.ToEditString((double)value)); default: return(value.ToString()); } }
public KeyValuePair <string, string> [] GetReportLines() { DataQueryResult qSet = ExecuteReport(); IList <DataField> dataFields = GetReportFields(); List <KeyValuePair <string, string> > ret = new List <KeyValuePair <string, string> > (); double total = 0; Dictionary <DataField, int> dataFieldsIndices = new Dictionary <DataField, int> (dataFields.Count); foreach (DataField dataField in dataFields) { for (int i = 0; i < qSet.Columns.Length; i++) { if (qSet.Columns [i].Field.StrongField == dataField) { dataFieldsIndices.Add(dataField, i); break; } } } foreach (LazyTableDataRow row in qSet.Result) { foreach (KeyValuePair <DataField, int> dataFieldIndex in dataFieldsIndices) { object value = row [dataFieldIndex.Value]; string text; string textValue = null; switch (dataFieldIndex.Key) { case DataField.OperationNumber: text = Translator.GetString("Document:"); textValue = Operation.GetFormattedOperationNumber(Convert.ToInt64(value)); break; case DataField.OperationDateTime: case DataField.OperationTimeStamp: text = Translator.GetString("Date/Time:"); textValue = BusinessDomain.GetFormattedDateTime(Convert.ToDateTime(value)); break; case DataField.UserName: case DataField.OperationsOperatorName2: text = Translator.GetString("Operator:"); break; case DataField.OperationLocation2: text = Translator.GetString("Location:"); break; case DataField.OperationPartner2: text = Translator.GetString("Client:"); break; case DataField.OperationTotal: case DataField.PaymentAmount: double sum = Convert.ToDouble(value); text = Translator.GetString("Amount:"); textValue = Currency.ToString(sum, PriceType.Unknown); total += sum; break; case DataField.OperationType: text = Translator.GetString("Type:"); textValue = Translator.GetOperationTypeName((OperationType)value); break; case DataField.PaymentTypesName: text = Translator.GetString("Type:"); break; case DataField.PartnerName: text = Translator.GetString("Partner:"); break; default: continue; } if (string.IsNullOrEmpty(textValue)) { textValue = value.ToString(); int index; if (string.IsNullOrEmpty(textValue) && dataFieldsIndices.TryGetValue(dataFieldIndex.Key, out index)) { textValue = (row [index] ?? string.Empty).ToString(); } } ret.Add(new KeyValuePair <string, string> (text, textValue)); } ret.Add(new KeyValuePair <string, string> (DriverBase.SEPARATOR, DriverBase.SEPARATOR)); } if (total > 0) { ret.Add(new KeyValuePair <string, string> (Translator.GetString("Total:"), Currency.ToString(total, PriceType.Unknown))); } return(ret.ToArray()); }