예제 #1
0
 public static void DbOpreation2(Func<BusinessResult> action)
 {
     var result = action();
     if (result.ResultType < 0)
     {
         throw new DbException(result.ResultMessage);
     }
 }
예제 #2
0
 public static void DbOpreation(Func<DataCriteria> action)
 {
     var result = action();
     if (result != null && result.ResultType != 0)
     {
         throw new DbException(result.GetMessage());
     }
 }
예제 #3
0
        public static ActionResult Execute(Func<ActionResult> call, Func<Exception, ActionResult> exceptionCall)
        {
            try
            {
                return call();
            }
            catch (Exception ex)
            {

                return exceptionCall(ex);
            }
        }
예제 #4
0
 public static void DbTransaction(Func<BusinessResult> action)
 {
     var trans = BusinessPortal.BeginTransaction();
     try
     {
         DbOpreation(action);
         trans.Commit();
     }
     catch
     {
         trans.Rollback();
         throw;
     }
 }
예제 #5
0
        public static string DataRowToCSV(List<ExportInfo> exportInfos, DataRow dr, Func<string,object, object> setValue =null)
        {
            string result = string.Empty;
            StringBuilder stringBuilder = new StringBuilder();

            foreach (ExportInfo exportInfo in exportInfos)
            {
                DataColumn dc = dr.Table.Columns[exportInfo.FileName];
                if (dc == null)
                {
                    throw new NotSupportedException(string.Format("{0} 上未发现 DataColumn 定义", exportInfo.FileName));
                }

                object dcValue = dr[exportInfo.FileName];
                if (setValue != null)
                {
                    dcValue = setValue(exportInfo.FileName,dcValue);
                }
                switch (dc.DataType.Name)
                {
                    case "String":
                        if (dcValue != null && dcValue != DBNull.Value)
                        {
                            stringBuilder.Append("=\"" + (string)dcValue + "\"\t");
                        }
                        else
                        {
                            stringBuilder.Append("\t");
                        }
                        break;
                    case "DateTime":
                        if (dcValue != null && dcValue != DBNull.Value)
                        {
                            stringBuilder.Append(((DateTime)dcValue).ToString(exportInfo.FormatString) + "\t");
                        }
                        else
                        {
                            stringBuilder.Append("\t");
                        }
                        break;
                    case "Boolean":
                        if (dcValue != null && dcValue != DBNull.Value)
                        {
                            stringBuilder.Append(((bool)dcValue) ? "YES\t" : "NO\t");
                        }
                        else
                        {
                            stringBuilder.Append("\t");
                        }
                        break;
                    #region 特殊处理
                    case "Int32":
                        if (dcValue != null && dcValue != DBNull.Value)
                        {
                            if (dcValue.ToString() == string.Empty)
                            {
                                stringBuilder.Append("0\t");
                            }
                            else
                            {
                                stringBuilder.Append(dcValue.ToString() + "\t");
                            }
                        }
                        else
                        {
                            stringBuilder.Append("0\t");
                        }
                        break;
                    case "Decimal":
                        if (dcValue != null && dcValue != DBNull.Value)
                        {
                            if (dcValue.ToString() == string.Empty)
                            {
                                stringBuilder.Append("0.00%\t");
                            }
                            else
                            {
                                stringBuilder.Append(dcValue.ToString() + "%\t");
                            }
                        }
                        else
                        {
                            stringBuilder.Append("0.00%\t");
                        }
                        break;
                    #endregion
                    default:
                        if (dcValue != null && dcValue != DBNull.Value)
                        {
                            stringBuilder.Append(dcValue.ToString() + "\t");
                        }
                        else
                        {
                            stringBuilder.Append("\t");
                        }
                        break;
                }
            }

            result = stringBuilder.ToString();

            if (!string.IsNullOrWhiteSpace(result))
            {
                result = result.Substring(0, result.Length - 1);
            }
            return result;
        }
예제 #6
0
 public static int DataTableExportToCSV(string fileName, List<ExportInfo> exportInfos, Type resourceType, DataTable dt, Func<string, object, object> setValue = null)
 {
     int result = 0;
     using (var writer = new StreamWriter(fileName, false, Encoding.Unicode))
     {
         result = DataTableExportToCSV(writer, exportInfos, resourceType, dt,setValue);
         writer.Close();
     }
     return result;
 }
예제 #7
0
 public static int DataTableExportToCSV(StreamWriter writer, List<ExportInfo> exportInfos, Type resourceType, DataTable dt, Func<string, object, object> setValue = null)
 {
     if (dt.Rows == null || dt.Rows.Count <= 0)
     {
         return -1;
     }
     StringBuilder stringBuilder = new StringBuilder();
     stringBuilder.AppendLine(TitleToCSV(exportInfos, resourceType));
     foreach (DataRow dr in dt.Rows)
     {
         string drCSV = DataRowToCSV(exportInfos, dr, setValue);
         if (!string.IsNullOrWhiteSpace(drCSV))
         {
             stringBuilder.AppendLine(drCSV);
         }
     }
     writer.Write(stringBuilder.ToString());
     return 0;
 }