/// <summary> /// lấy dữ liệu từ tuần hiện tại tên tình trạng xử lý và datatable đã lấy từ camlquery /// </summary> /// <param name="tuan"></param> /// <param name="name"></param> /// <param name="dt"></param> /// <param name="user"></param> /// <returns></returns> public static SeriesPS GetDataByLinQ(int tuan, string name, DataTable dt, string[] user) { SeriesPS data = new SeriesPS(); //DateTime firstDayOfWeek = GetFirstDayOfWeek(DateTime.Now.Year.ToString(), tuan); //DateTime lastDayOfWeek = GetLastDayOfWeek(DateTime.Now.Year.ToString(), tuan); DateTime now = DateTime.Now; DateTime firstDayOfMonth = new DateTime(now.Year, now.Month, 1); DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); List<int> count = new List<int>(); switch (name) { case "Đang xử lý": for (int i = 0; i < user.Length; i++) { int _countDangXuLy = dt.AsEnumerable().Where(x => !string.IsNullOrEmpty(x.Field<string>("NguoiThucHien")) && x.Field<string>("NguoiThucHien").Contains(user[i]) && ((!x.Field<DateTime?>("HanHoanThanh").HasValue) || (x.Field<DateTime?>("HanHoanThanh").HasValue && x.Field<DateTime>("HanHoanThanh").Date >= firstDayOfMonth.Date))).Count(); count.Add(_countDangXuLy); } data.name = "Đang xử lý"; data.data = count.ToArray(); break; case "Đã chuyển xử lý": for (int i = 0; i < user.Length; i++) { int _countChuyenXuLy = dt.AsEnumerable().Where(x => !string.IsNullOrEmpty(x.Field<string>("DaKetThuc")) && x.Field<string>("DaKetThuc").Equals("0") && !string.IsNullOrEmpty(x.Field<string>("NguoiChuyenXuLy")) && x.Field<string>("NguoiChuyenXuLy").Contains(user[i]) && (x.Field<DateTime?>("NgayChuyenXuLy").HasValue && x.Field<DateTime>("NgayChuyenXuLy").Date >= firstDayOfMonth.Date && x.Field<DateTime>("NgayChuyenXuLy").Date <= lastDayOfMonth.Date)).Count(); count.Add(_countChuyenXuLy); } data.name = "Đã chuyển xử lý"; data.data = count.ToArray(); break; case "Đã xử lý": for (int i = 0; i < user.Length; i++) { int _countDaXuLy = dt.AsEnumerable().Where(x => !string.IsNullOrEmpty(x.Field<string>("DaKetThuc")) && x.Field<string>("DaKetThuc").Equals("1") && !string.IsNullOrEmpty(x.Field<string>("NguoiDaThucHien")) && x.Field<string>("NguoiDaThucHien").Contains(user[i]) && (x.Field<DateTime?>("NgayKetThuc").HasValue && x.Field<DateTime>("NgayKetThuc").Date >= firstDayOfMonth.Date && x.Field<DateTime>("NgayKetThuc").Date <= lastDayOfMonth.Date)).Count(); count.Add(_countDaXuLy); } data.name = "Đã xử lý"; data.data = count.ToArray(); break; } return data; }
private void Page_Load(object sender, EventArgs e) { try { DateTime today = DateTime.Now; int tuan = GetWeekOrderInYear(today); DateTime firstDay = GetFirstDayOfWeek(DateTime.Now.Year.ToString(), tuan); DateTime lastDay = GetLastDayOfWeek(DateTime.Now.Year.ToString(), tuan); DateTime now = DateTime.Now; DateTime fd = new DateTime(now.Year, now.Month, 1); DateTime ld = fd.AddMonths(1).AddDays(-1); string[] user; //categories.Tuan1 = "Tuần " + (tuan - 3); //categories.Tuan2 = "Tuần " + (tuan - 2); //categories.Tuan3 = "Tuần " + (tuan - 1); //categories.Tuan4 = "Tuần " + (tuan); //categoryStr = ConvertObjectToJson(categories); string url = Tandan.Utilities.Utility.GetAbsoluteSiteUrl(this.SiteUrl); using (SPSite site = new SPSite(url)) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists["CongViec"]; SPQuery query = new SPQuery(); query.Query = string.Concat("<Where>", "<Or>", "<IsNull>", "<FieldRef Name='HanHoanThanh'/>", "</IsNull>", "<And>", "<IsNotNull>", "<FieldRef Name='HanHoanThanh'/>", "</IsNotNull>", "<Geq>", "<FieldRef Name='HanHoanThanh'/>", "<Value IncludeTimeValue='FALSE' Type='DateTime'>" + fd.ToString("yyyy-MM-ddThh:mm:ssZ") + "</Value>", "</Geq>", "</And>", "</Or>", "</Where>", "<OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy>"); query.ViewFields = string.Concat("<FieldRef Name='ID'/>", "<FieldRef Name='NgayBatDau'/>", "<FieldRef Name='NguoiThucHien'/>", "<FieldRef Name='DaKetThuc'/>", "<FieldRef Name='HanHoanThanh'/>", "<FieldRef Name='NgayKetThuc'/>", "<FieldRef Name='NgayChuyenXuLy'/>", "<FieldRef Name='NguoiChuyenXuLy'/>", "<FieldRef Name='NguoiDaThucHien'/>"); query.ViewFieldsOnly = true; getUser = GetUser(web.CurrentUser.ToString()); //category = getUser.HoVaTen; category = ConvertObjectToJson(getUser.HoVaTen); SPListItemCollection items = list.GetItems(query); if (items != null && items.Count != 0) { DataTable dtGetData = items.GetDataTable(); user = getUser.User; DangXuLy = GetDataByLinQ(tuan, "Đang xử lý", dtGetData, user); ChuyenXuLy = GetDataByLinQ(tuan, "Đã chuyển xử lý", dtGetData, user); DaXuLy = GetDataByLinQ(tuan, "Đã xử lý", dtGetData, user); DangXuLyStr = ConvertObjectToJson(DangXuLy); ChuyenXuLyStr = ConvertObjectToJson(ChuyenXuLy); DaXuLyStr = ConvertObjectToJson(DaXuLy); } } } } catch (Exception ex) { //TextBox1.Text = ex.ToString(); } }