public DataTable GetWeekDatas()
{
string[] fields = { "Province", "City", "UserName", "RealName", "Mobile", "UpdateWeek" };
DataTable result = new DataTable();
DataRow dr;
for (int i = 0; i < fields.Length; i++)
{
result.Columns.Add(fields[i]);
}
DataRepotHelper dbHelper = new DataRepotHelper();
// string tableID = this.ddlWeekTable.SelectedValue;
DateTime currentDate = new DateTime(2013, 6, 15);
DateTime startDate = new DateTime(2012, 12, 29);
// DateTime.Compare(currentDate, startDate);
string[] tableids = { "08" };
while (DateTime.Compare(currentDate, startDate) >= 0)
{
for (int m = 0; m < tableids.Length; m++)
{
string updateWeek = GetWeekCode(startDate);
string sql = string.Format(@"select d.Name as Province,e.Name as City, u.UserName,u.RealName,u.Mobile,'{0}' as UpdateWeek from Sys_OilDepotInfo as a left join (select * from Sys_ReportData_08 where UpdateWeek='{1}') as b on a.ID=b.objectID left join Rel_User_SurveyTable as r
on a.ID=r.objectID left join sys_user as u on r.userID=u.Id left join dic_district as d on u.ProvinceID=d.ID left join dic_district as e on u.CityID=e.ID
where u.isValid=1 and r.TableID='{2}' and b.ID is NULL", updateWeek, updateWeek, tableids[m]);
DataTable dt = dbHelper.GetDataTable(sql);
if (dt != null)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
dr = result.NewRow();
for (int k = 0; k < fields.Length; k++)
{
dr[fields[k]] = dt.Rows[j][fields[k]];
}
DataView dv = result.DefaultView;
dv.RowFilter = " UpdateWeek='" + updateWeek + "' and userName='" + dr["userName"].ToString() + "' and RealName='" + dr["RealName"].ToString() + "'";
if (dv.Count <= 0)
{
result.Rows.Add(dr);
}
}
}
}
startDate = startDate.AddDays(7);
}
return result;
}