private void btnSave_Click(object sender, EventArgs e) { List <SortProductScheduleViewModel> sortPSSVMs = new List <SortProductScheduleViewModel>(); foreach (DataGridViewRow dr in adgv.Rows) { if (dr.Cells[0].Value != null) { SortProductScheduleViewModel spps = new SortProductScheduleViewModel(); spps.Id = (int)dr.Cells[0].Value; spps.ProductName = dr.Cells[2].Value.ToString(); spps.ShowTime = dr.Cells[3].Value.ToString(); spps.ShowDate = dr.Cells[4].Value.ToString(); spps.ContractDetailId = (int)dr.Cells[1].Value; spps.TimeSlot = dr.Cells[6].Value.ToString(); spps.TimeSlotLength = (int)dr.Cells[7].Value; spps.Quantity = (int)dr.Cells[5].Value; spps.OrderNumber = (int)dr.Cells[8].Value; spps.ShowTimeInt = (int)dr.Cells[9].Value; sortPSSVMs.Add(spps); } } if (sortPSSVMs.Count > 0) { try { _productScheduleShowService = new ProductScheduleShowService(); foreach (var pssVM in sortPSSVMs) { var dbPss = _productScheduleShowService.GetById(pssVM.Id); if (dbPss != null) { dbPss.OrderNumber = pssVM.OrderNumber; _productScheduleShowService.EditProductScheduleShow(dbPss); } } Utilities.ShowMessage("Cập nhật thành công"); Logging.LogBusiness(string.Format("{0} {1} {2}", Common.Session.GetUserName(), Common.Constants.LogAction.Update, "thứ tự phát sóng của lịch chiếu ngày " + dtpOneDate.Value), Common.Constants.BusinessLogType.Update); } catch (Exception ex) { throw; } finally { _productScheduleShowService = null; } } }
private void btnSort_Click(object sender, EventArgs e) { try { List <SortProductScheduleViewModel> sortPSSVMs = new List <SortProductScheduleViewModel>(); foreach (DataGridViewRow dr in adgv.Rows) { if (dr.Cells[0].Value != null) { SortProductScheduleViewModel spps = new SortProductScheduleViewModel(); spps.Id = (int)dr.Cells[0].Value; spps.ProductName = dr.Cells[2].Value.ToString(); spps.ShowTime = dr.Cells[3].Value.ToString(); spps.ShowDate = dr.Cells[4].Value.ToString(); spps.ContractDetailId = (int)dr.Cells[1].Value; spps.TimeSlot = dr.Cells[6].Value.ToString(); spps.TimeSlotLength = (int)dr.Cells[7].Value; spps.Quantity = (int)dr.Cells[5].Value; spps.OrderNumber = (int)dr.Cells[8].Value; spps.ShowTimeInt = (int)dr.Cells[9].Value; sortPSSVMs.Add(spps); } } if (sortPSSVMs.Count > 0) { sortPSSVMs = sortPSSVMs.OrderBy(s => s.ShowTimeInt) .ThenBy(s => s.OrderNumber).ToList(); SortableBindingList <SortProductScheduleViewModel> sbl = new SortableBindingList <SortProductScheduleViewModel>(sortPSSVMs); bs = new BindingSource(); bs.DataSource = sbl; adgv.DataSource = bs; } } catch (Exception ex) { throw; } }