private void adgv_CellClick(object sender, DataGridViewCellEventArgs e) { if (adgv.SelectedRows.Count > 0) { var selectedRow = adgv.SelectedRows[0]; //Prepare model if (selectedRow.Cells[0].Value.ToString() != "0" && !String.IsNullOrWhiteSpace(selectedRow.Cells[0].Value.ToString())) { productScheduleShowId = int.Parse(selectedRow.Cells[0].Value.ToString()); productScheduleShow = new ProductScheduleShow() { Id = (int)selectedRow.Cells[0].Value, ContractDetailId = model.Id, TimeSlotLength = (int)cboDuration.SelectedValue, ProductName = txtFileName.Text, ShowTypeId = (int)cboShowType.SelectedValue }; } else { productScheduleShowId = 0; } } }
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 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 { } }
public ProductScheduleDetailForm(ProductScheduleShow inputModel, string contractCode) { this.model = inputModel; if (model != null) { ProductName = inputModel.ProductName; ShowTypeId = inputModel.ShowTypeId; } InitializeComponent(); LoadCboPosition(); CompleteLoadData = 0; LoadTimeSlots(); GetCostRule(); LoadData(); SetMinMaxDateMonthPicker(contractCode); }
public int EditProductScheduleShow(ProductScheduleShow input) { int result = CRUDStatusCode.ERROR; var ProductScheduleShow = _ProductScheduleShowRepository.GetById(input.Id); if (ProductScheduleShow != null) { ProductScheduleShow.ContractDetailId = input.ContractDetailId; ProductScheduleShow.Cost = input.Cost; ProductScheduleShow.ProductName = input.ProductName; ProductScheduleShow.ShowTime = input.ShowTime; ProductScheduleShow.Quantity = input.Quantity; ProductScheduleShow.TimeSlotLength = input.TimeSlotLength; ProductScheduleShow.ShowDate = input.ShowDate; ProductScheduleShow.TimeSlot = input.TimeSlot; ProductScheduleShow.TotalCost = input.TotalCost; ProductScheduleShow.Discount = input.Discount; ProductScheduleShow.OrderNumber = input.OrderNumber; bool isExisted = _ProductScheduleShowRepository.Exist(t => t.ContractDetailId == input.ContractDetailId && t.ProductName == input.ProductName && t.ShowDate == input.ShowDate && t.TimeSlot == input.TimeSlot && t.Quantity == input.Quantity && t.TimeSlotLength == input.TimeSlotLength && t.OrderNumber == input.OrderNumber); if (!isExisted) { _ProductScheduleShowRepository.Update(ProductScheduleShow); result = CRUDStatusCode.SUCCESS; } else { result = CRUDStatusCode.EXISTED; } } return(result); }
public int AddProductScheduleShow(ProductScheduleShow input) { int result = CRUDStatusCode.ERROR; if (input != null) { bool isExisted = _ProductScheduleShowRepository.Exist(t => t.ContractDetailId == input.ContractDetailId && t.TimeSlotLength == input.TimeSlotLength && t.TimeSlot == input.TimeSlot && t.ShowDate == input.ShowDate); if (!isExisted) { _ProductScheduleShowRepository.Add(input); result = CRUDStatusCode.SUCCESS; } else { result = CRUDStatusCode.EXISTED; } } return(result); }
private void btnSave_Click(object sender, EventArgs e) { try { ContractItem result = null; int editResult = CRUDStatusCode.ERROR; _contractDetailService = new ContractItemService(); if (model != null) { if (model.Id == 0) { if (_contractDetailService.AbleToAddWithFileName(txtFileName.Text.Trim())) //Not has ACTIVE used before => Able to add { //---------Add--------- model.ProductName = txtProductName.Text.Trim(); model.TotalCost = Utilities.GetDoubleFromTextBox(txtTotalCost); model.DurationSecond = (int)cboDuration.SelectedValue; model.FileName = txtFileName.Text.Trim(); model.NumberOfShow = Utilities.GetIntFromTextBox(txtNumberOfShow); model.ShowTypeId = (int)cboShowType.SelectedValue; result = _contractDetailService.CreateContractDetail(model); if (result != null) { if (result.Id == 0) { Utilities.ShowMessage(CommonMessage.EXISTED_PRODUCT_IN_CONTRACT); } else { model = result; gbRegisterSchedule.Visible = true; productScheduleShow = new ProductScheduleShow() { ContractDetailId = model.Id, TimeSlotLength = (int)cboDuration.SelectedValue, ProductName = txtFileName.Text.Trim() }; Utilities.ShowMessage(CommonMessage.ADD_SUCESSFULLY); Logging.LogBusiness(string.Format("{0} {1} {2}", Common.Session.GetUserName(), Common.Constants.LogAction.Create, "sản phẩm thuộc hợp đồng mã " + model.ContractCode), Common.Constants.BusinessLogType.Create); } } } else { //Has ACTIVE used before => Not Able to add Utilities.ShowMessage(CommonMessage.FILENAME_IS_USED); } } else { if (_contractDetailService.AbleToEditWithFileName(txtFileName.Text.Trim(), model.Id)) //Not has ACTIVE used before => Able to add { //---------Edit--------- model.ProductName = txtProductName.Text.Trim(); model.TotalCost = Utilities.GetDoubleFromTextBox(txtTotalCost); model.NumberOfShow = Utilities.GetIntFromTextBox(txtNumberOfShow); model.FileName = txtFileName.Text.Trim(); model.ShowTypeId = (int)cboShowType.SelectedValue; model.DurationSecond = (int)cboDuration.SelectedValue; editResult = _contractDetailService.EditContractDetail(model); if (editResult == CRUDStatusCode.SUCCESS) { gbRegisterSchedule.Visible = true; Utilities.ShowMessage(CommonMessage.EDIT_SUCESSFULLY); Logging.LogBusiness(string.Format("{0} {1} {2}", Common.Session.GetUserName(), Common.Constants.LogAction.Update, "sản phẩm thuộc hợp đồng mã " + model.ContractCode), Common.Constants.BusinessLogType.Update); } } else { //Has ACTIVE used before => Not Able to add Utilities.ShowMessage(CommonMessage.FILENAME_IS_USED); } } } } catch (Exception ex) { throw; } finally { _contractDetailService = 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; } }