欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

将从mysql数据库查询的信息,遍历到List<>以及一些随机数的生成

程序员文章站 2022-03-10 18:26:44
将从mysql数据库查询的信息,遍历到List<>以及一些随机数的生成。 代码比较乱,但是方法还是对的,大家又需要的选择看,希望对博友 有帮助,欢迎留言分享! public class subject { public string sub { get; set; } } //public clas ......

 

将从mysql数据库查询的信息,遍历到List<>以及一些随机数的生成。

代码比较乱,但是方法还是对的,大家又需要的选择看,希望对博友 有帮助,欢迎留言分享!

public class subject { public string sub { get; set; } }
//public class QueryCategory {
// subject s = new subject();
// string m = s.sub;
// string Sql = "select Category from httang_test.hxwang_office where Subject = '" + m.ToString()+"";
// DataTable dt1 = MySqlDBHelper.QueryDataTable(Sql);
//}
static List<Task> GenerateTasks()
{
// List<string> ShoppingTasks = new List<string>();
// List<string> OfficeTasks = new List<string>();

List<string> HouseTasks = new List<string>();
TaskInfoControl t = new TaskInfoControl();
DataTable dt = t.QuerySubject();
foreach (DataRow item in dt.Rows)//循环取出ds.table中的值
{
subject s = new subject(); // 实例化subject对象
try
{
s.sub = Convert.ToString(item["Subject"]);//将表中Subject这列值给s.sub
}
catch (Exception e)
{
throw e;
}
HouseTasks.Add(s.sub); // 将取出的对象保存在LIST中 以上是获得值。
// ShoppingTasks.Add(s.sub);
// OfficeTasks.Add(s.sub);
}

string ts = null;
for (int i = 0; i < HouseTasks.Count; i++)
{
string m = HouseTasks[i];
TaskInfoControl tic = new TaskInfoControl();
DataTable hc = tic.QueryCaregory(m);
ts = Convert.ToString(hc); //将DataTable转换成string
}
//将string 转换成枚举类型
// var enu = Enum.Parse(typeof(int), ts);

// 前面那列数据
List<Task> ret = new List<Task>();
foreach (string s in HouseTasks)//遍历数组
ret.Add(TaskGenerator.CreateTask(s, TaskCategory.HouseChores));
return ret;
}
//for (int i = 0; i < TaskGenerator.CustomerCount; i++)
// foreach (string s in OfficeTasks)
// ret.Add(TaskGenerator.CreateTask(s, TaskCategory.Office));
// foreach (string s in ShoppingTasks)
// ret.Add(TaskGenerator.CreateTask(s, TaskCategory.Shopping));

//for (int i = 0; i<dt.Rows.Count; i++) //循环取出ds.table中的值
//{
// subject s = new subject(); // 实例化student对象
// s.sub = Convert.ToString(dt);
// HouseTasks.Add(s.sub);
// ShoppingTasks.Add(s.sub);
// OfficeTasks.Add(s.sub); // 将取出的对象保存在LIST中 以上是获得值。
//}
internal class TaskGenerator
{
public static int CustomerCount = 10;
//随机数
static Random rndGenerator = new Random();
public static Task CreateTask(string subject, TaskCategory category)
{
Task task = new Task(subject, category, DateTime.Now.AddHours(-rndGenerator.Next(96)));
int rndStatus = rndGenerator.Next(10);
//TotalHours表示总小数时
if (task.TimeDiff.TotalHours > 12)
{
if (task.TimeDiff.TotalHours > 80)
{
task.Status = TaskStatus.Completed;
}
else
{
//随机生成一个百分比放入进度条
task.Status = TaskStatus.InProgress;
task.PercentComplete = rndGenerator.Next(9) * 10;
}
//随机生成日期
task.StartDate = task.CreatedDate.AddMinutes(rndGenerator.Next(720)).Date;
}
if (rndStatus != 5)
task.DueDate = task.CreatedDate.AddHours((90 - rndStatus * 9) + 24).Date;
if (rndStatus > 8)
task.Priority = 2;
if (rndStatus < 3)
task.Priority = 0;
if (rndStatus == 6 && task.Status == TaskStatus.InProgress)
task.Status = TaskStatus.Deferred;
if (rndStatus == 4 && task.Status == TaskStatus.InProgress && task.PercentComplete < 40)
task.Status = TaskStatus.WaitingOnSomeoneElse;
if (task.Status == TaskStatus.Completed)
{
if (!task.StartDate.HasValue)
task.StartDate = task.CreatedDate.AddHours(12).Date;
task.CompletedDate = task.StartDate.Value.AddHours(rndGenerator.Next(48) + 24);
}
return task;
}