示例#1
0
文件: Unity.cs 项目: manny2016/cpr
 public static SqlDataRecord ConvertforTeamLevel(ExcelSignleRow row, DataSourceNames name)
 {
     var record = new SqlDataRecord(Constants.Structures[name]);
     for (var index = 0; index < Constants.Structures[name].Length; index++)
     {
         var month = row.JMetadata.TryGetValue<string>("$.Month");
         var week = row.JMetadata.TryGetValue<string>("$.Week");
         if (month == null && lastMonth != string.Empty)
             month = lastMonth;
         if (month != null && month.IndexOf("Grand Total") >= 0) return null;
         if (string.IsNullOrEmpty(week))
             week = "Week 1";
         switch (Constants.Structures[name][index].Name)
         {
             case "Monthly":
                 record.SetStringIfNullOrEmpty(index, month);
                 break;
             case "Weekly":
                 record.SetStringIfNullOrEmpty(index, week);
                 break;
             case "IsTotalLine":
                 record.SetBoolean(index, month.IndexOf("Total") >= 0);
                 break;
             case "BatchJobId":
                 record.SetStringIfNullOrEmpty(index, row.BatchJob?.Id);
                 break;
             case "Metadata":
                 record.SetStringIfNullOrEmpty(index, row.JMetadata?.ToString());
                 break;
         }
         if (month != null)
             lastMonth = month;
     }
     return record;
 }
示例#2
0
文件: Unity.cs 项目: manny2016/cpr
 public static SqlDataRecord Convert(TeamLevelReport report, DataSourceNames name)
 {
     var record = new SqlDataRecord(Constants.Structures[name]);
     for (var index = 0; index < Constants.Structures[name].Length; index++)
     {
         switch (Constants.Structures[name][index].Name)
         {
             case "Monthly":
                 record.SetStringIfNullOrEmpty(index, report.Monthly);
                 break;
             case "Weekly":
                 record.SetStringIfNullOrEmpty(index, report.Weekly);
                 break;
             case "IsTotalLine":
                 record.SetBoolean(index, report.IsTotalLine);
                 break;
             case "BatchJobId":
                 record.SetStringIfNullOrEmpty(index, report.BatchJob);
                 break;
             case "Metadata":
                 record.SetStringIfNullOrEmpty(index, report.Metadata);
                 break;
         }
     }
     return record;
 }
示例#3
0
文件: Unity.cs 项目: manny2016/cpr
        public static SqlDataRecord Convert(ExcelSignleRow row, DataSourceNames name)
        {
            try
            {
                if (row == null) throw new ArgumentNullException("data can't be null in convert");
                if (row.PrimaryKeyRequired(name) == false)
                {
                    throw new NullReferenceException($"Primary Key can't be null{name}");
                }
                var record = new SqlDataRecord(Constants.Structures[name]);
                for (var index = 0; index < Constants.Structures[name].Length; index++)
                {
                    var fieldName = Constants.Structures[name][index].Name;
                    var property = row.Properties.TryFirst(o => o.Descriptor.FiledName.Equals(fieldName, StringComparison.OrdinalIgnoreCase));
                    if (property == null)
                        record.SetDBNull(index);
                    else
                    {

                        if (property.Descriptor.Type == System.Data.SqlDbType.DateTime)
                        {
                            if (property.Value.TryToUnixStampDateTime(out long? timestamp))
                            {
                                record.SetInt64(index, timestamp ?? 0);
                            }
                            else
                            {
                                record.SetDBNull(index);
                            }
                        }
                        else if (property.Descriptor.Type == System.Data.SqlDbType.Int)
                        {
                            if (int.TryParse(property.Value?.ToString(), out int val))
                            {
                                record.SetInt32(index, val);
                            }
                            else
                            {
                                record.SetDBNull(index);
                            }
                        }
                        else if (property.Descriptor.Type == System.Data.SqlDbType.Money)
                        {
                            if (decimal.TryParse(property.Value?.ToString(), out decimal money))
                            {
                                record.SetSqlMoney(index, money);
                            }
                            else
                            {
                                record.SetDBNull(index);
                            }
                        }
                        else
                        {
                            record.SetStringIfNullOrEmpty(index, property.Value?.ToString());
                        }
                    }
                }
                return record;
            }
            catch (Exception ex)
            {
                return null;
            }
        }