private void btnDeleteSchedule_Click(object sender, EventArgs e) { try { if (productScheduleShowId != 0) { if (Utilities.ShowConfirmMessage(CommonMessage.CONFIRM_DELETE)) { _productScheduleShowService = new ProductScheduleShowService(); //Completely delete from DB _productScheduleShowService.DeleteProductScheduleShow(productScheduleShowId); UpdateContractDetailTotalCost(); LoadDGV(); Logging.LogBusiness(string.Format("{0} {1} {2}", Common.Session.GetUserName(), Common.Constants.LogAction.Delete, "sản phẩm thuộc hợp đồng mã " + model.ContractCode), Common.Constants.BusinessLogType.Delete); } } } catch (Exception) { throw; } finally { _productScheduleShowService = null; } }
private int AddProductSchedultShows(DateTime[] selectedDates, ProductScheduleShow originModel) { int result = CRUDStatusCode.ERROR; try { _productScheduleShowService = new ProductScheduleShowService(); using (var context = new ATVEntities()) { using (DbContextTransaction transaction = context.Database.BeginTransaction()) { try { var pssInDB = context.ProductScheduleShows.Where(p => p.ContractDetailId == model.ContractDetailId && p.TimeSlot == model.TimeSlot && p.TimeSlotCode == model.TimeSlotCode && p.TimeSlotLength == model.TimeSlotLength) .ToList(); if (pssInDB != null) { foreach (var item in pssInDB) { context.ProductScheduleShows.Remove(item); context.SaveChanges(); } } ProductScheduleShow pss = null; foreach (var date in selectedDates) { pss = originModel; pss.ShowDate = date; context.ProductScheduleShows.Add(pss); context.SaveChanges(); } transaction.Commit(); result = CRUDStatusCode.SUCCESS; } catch (Exception ex) { transaction.Rollback(); throw; } } } } catch (Exception ex) { throw; } finally { _productScheduleShowService = null; } return(result); }
public void LoadData() { try { if (model != null) { txtTimeSlotLength.Text = model.TimeSlotLength.ToString(); if (model.Id != 0) { _productScheduleShowService = new ProductScheduleShowService(); model = _productScheduleShowService.GetById(model.Id); if (model != null) { mpShowDate.Text = model.ShowDate.ToString("dd/MM/YYYY"); cboTimeSlot.Text = model.TimeSlot; txtSumCost.Text = Utilities.DoubleMoneyToText(model.Cost); //txtTotalCost.Text = Utilities.DoubleMoneyToText(model.TotalCost); //txtDiscount.Text = model.Discount.ToString(); cboPosition.SelectedValue = model.OrderNumber; txtTimeSlotLength.Text = model.TimeSlotLength.ToString(); txtQuantity.Text = model.Quantity.ToString(); if (model.IsAdvanced) { ckbPosition.Checked = true; txtCost.Text = Utilities.DoubleMoneyToText(model.Cost); } else { ckbPosition.Checked = false; } model.ProductName = ProductName; //Load selected dates var selectedDates = _productScheduleShowService.GetAllSelectedDatesByContractDetailIdAndTimeSlotCode(model.ContractDetailId, model.TimeSlotCode); if (selectedDates != null) { mpShowDate.BoldedDates = selectedDates; txtQuantity.Text = mpShowDate.BoldedDates.Count().ToString(); CalculateCost(); } } } CalculateCost(); } } catch (Exception ex) { Logging.LogSystem(ex.StackTrace, SystemLogType.Exception); throw; } finally { _productScheduleShowService = null; } }
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 LoadDGV() { try { if (model.Id != 0) { var productScheduleShows = new ProductScheduleShowService().GetAllVMForList(model.Id); SortableBindingList <ProductScheduleShowViewModel> sbl = new SortableBindingList <ProductScheduleShowViewModel>(productScheduleShows); bs = new BindingSource(); bs.DataSource = sbl; adgv.DataSource = bs; adgv.Columns["Id"].Visible = false; adgv.Columns["ContractDetailId"].Visible = false; adgv.Columns["ProductName"].Visible = false; adgv.Columns["ShowTime"].Visible = false; adgv.Columns["Discount"].Visible = false; adgv.Columns["TotalCost"].Visible = false; adgv.Columns["ShowDate"].HeaderText = ADGVText.ShowDate; adgv.Columns["ShowDate"].Width = ControlsAttribute.GV_WIDTH_NORMAL; adgv.Columns["TimeSlot"].HeaderText = ADGVText.TimeSlot; adgv.Columns["TimeSlot"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; adgv.Columns["Quantity"].HeaderText = ADGVText.NumberOfShow; adgv.Columns["Quantity"].Width = ControlsAttribute.GV_WIDTH_SEEM; adgv.Columns["TimeSlotLength"].HeaderText = ADGVText.Duration; adgv.Columns["TimeSlotLength"].Width = ControlsAttribute.GV_WIDTH_SEEM; adgv.Columns["Cost"].HeaderText = ADGVText.Cost; adgv.Columns["Cost"].Width = ControlsAttribute.GV_WIDTH_NORMAL; adgv.Columns["Discount"].HeaderText = ADGVText.Discount; adgv.Columns["Discount"].Width = ControlsAttribute.GV_WIDTH_SEEM; adgv.Columns["TotalCost"].HeaderText = ADGVText.TotalCost; adgv.Columns["TotalCost"].Width = ControlsAttribute.GV_WIDTH_MEDIUM; productScheduleShow = new ProductScheduleShow() { ContractDetailId = model.Id, TimeSlotLength = model.DurationSecond, ProductName = txtFileName.Text//model.ProductName }; } } catch (Exception ex) { throw; } finally { } }
private void LoadDGV() { try { _productScheduleShowService = new ProductScheduleShowService(); List <SortProductScheduleViewModel> sortPSSVMs = _productScheduleShowService.GetAllVMSearchingList(searchModel); SortableBindingList <SortProductScheduleViewModel> sbl = new SortableBindingList <SortProductScheduleViewModel>(sortPSSVMs); bs = new BindingSource(); bs.DataSource = sbl; adgv.DataSource = bs; adgv.Columns["Id"].Visible = false; adgv.Columns["ContractDetailId"].Visible = false; adgv.Columns["Quantity"].Visible = false; adgv.Columns["ShowDate"].Visible = false; adgv.Columns["ShowTimeInt"].Visible = false; adgv.Columns["TimeSlotLength"].Visible = false; adgv.Columns["ProductName"].ReadOnly = true; adgv.Columns["TimeSlot"].ReadOnly = true; adgv.Columns["ShowTime"].ReadOnly = true; //adgv.Columns["ShowTime"].ToolTipText = "Thứ tự xuất hiện của quảng cáo: là một số có độ ưu tiên giảm dần từ 1 đến 7"; adgv.Columns["ShowTime"].ValueType = typeof(int); adgv.Columns["TimeSlot"].HeaderText = ADGVText.TimeSlot; adgv.Columns["TimeSlot"].Width = ControlsAttribute.GV_WIDTH_LARGE; adgv.Columns["ShowTime"].HeaderText = ADGVText.ShowTime; adgv.Columns["ShowTime"].Width = ControlsAttribute.GV_WIDTH_SEEM; adgv.Columns["ProductName"].HeaderText = ADGVText.ProductName; adgv.Columns["ProductName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; adgv.Columns["OrderNumber"].HeaderText = ADGVText.OrderNumber; adgv.Columns["OrderNumber"].Width = ControlsAttribute.GV_WIDTH_SEEM; } catch (Exception ex) { throw; } finally { _productScheduleShowService = null; } }
private void btnSave_Click(object sender, EventArgs e) { int result = CRUDStatusCode.ERROR; if ((int)cboPosition.SelectedValue != 4 && ckbPosition.Checked == true) { if (!Utilities.ShowConfirmMessage("Vị trí ưu tiên xuất hiện của những quảng cáo tạo/cập nhật sau sẽ chèn" + " lên trước những quảng cáo được tạo trước đó. Bạn có muốn tiếp tục lưu ?")) { return; } } try { _productScheduleShowService = new ProductScheduleShowService(); _timeSlotService = new TimeSlotService(); if (model != null) { TimeSlot selectedTimeSlot = _timeSlotService.GetById((int)cboTimeSlot.SelectedValue); if (selectedTimeSlot == null) { Utilities.ShowReturnMessage(result, "Thời điểm chọn không hợp lệ"); } else { //Add Edit ProductScheduleShow originModel = model; model.TimeSlot = cboTimeSlot.Text; model.TimeSlotCode = selectedTimeSlot.Code; model.TotalCost = (double)txtSumCost.MoneyValue; model.Cost = (double)txtCost.MoneyValue; model.OrderNumber = (int)cboPosition.SelectedValue; model.TimeSlotLength = int.Parse(txtTimeSlotLength.Text); model.Quantity = 1;//TODO: mặc định là 1 //int.Parse(txtQuantity.Text); model.IsAdvanced = ckbPosition.Checked; if (mpShowDate.BoldedDates.Length > 0) { model.ShowDate = mpShowDate.BoldedDates[0]; } else { model.ShowDate = DateTime.Now; } model.ProductName = ProductName; model.ShowTime = Utilities.GetHourFormInt(selectedTimeSlot.FromHour); model.ShowTimeInt = selectedTimeSlot.FromHour; result = AddProductSchedultShows(mpShowDate.BoldedDates, originModel); Utilities.ShowReturnMessage(result, "Lưu"); Logging.LogBusiness(string.Format("{0} {1} {2}", Common.Session.GetUserName(), Common.Constants.LogAction.Update, "lịch chiếu " + model.ProductName + " " + model.TimeSlot + " " + model.ContractDetailId), Common.Constants.BusinessLogType.Update); } } } catch (Exception ex) { Logging.LogSystem(ex.StackTrace, SystemLogType.Exception); throw; } finally { _timeSlotService = null; _productScheduleShowService = null; } }