private void LoadCboProductCode() { try { string contracCode = cboContractCode.SelectedValue + ""; var options = new ContractItemService().GetOptionsByContractCode(contracCode.Trim()); Utilities.LoadComboBoxOptions(cboProduct, options); } catch (Exception) { throw; } }
private void LoadData() { try { if (model != null) { if (model.Id != 0) { //Existed _contractDetailService = new ContractItemService(); model = _contractDetailService.GetById(model.Id); if (model != null) { IsExisted = true; txtProductName.Text = model.ProductName.Trim(); txtTotalCost.Text = Utilities.DoubleMoneyToText(model.TotalCost); txtNumberOfShow.Text = model.NumberOfShow.ToString(); txtFileName.Text = model.FileName.Trim().ToString(); cboDuration.SelectedValue = model.DurationSecond; cboShowType.SelectedValue = model.ShowTypeId; LoadDGV(); } } } else { gbRegisterSchedule.Visible = false; } } catch (Exception) { throw; } finally { _contractDetailService = null; IsLoadCompleted = true; } }
private void LoadDGV() { try { _contractItemService = new ContractItemService(); List <ContractItemViewModel> contractDetailVMs = _contractItemService.GetAllVMForListByContractCode(model.Code); SortableBindingList <ContractItemViewModel> sbl = new SortableBindingList <ContractItemViewModel>(contractDetailVMs); bs = new BindingSource(); bs.DataSource = sbl; adgv.DataSource = bs; adgv.Columns["Id"].Visible = false; adgv.Columns["StatusId"].Visible = false; adgv.Columns["CreateDate"].Visible = false; adgv.Columns["LastUpdateBy"].Visible = false; adgv.Columns["LastUpdateDate"].Visible = false; adgv.Columns["DurationSecond"].Visible = false; adgv.Columns["ContractCode"].HeaderText = ADGVText.BelongToContractCode; adgv.Columns["ContractCode"].Width = ControlsAttribute.GV_WIDTH_NORMAL; adgv.Columns["ProductName"].HeaderText = ADGVText.Name; adgv.Columns["ProductName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; adgv.Columns["NumberOfShow"].HeaderText = ADGVText.NumberOfShow; adgv.Columns["NumberOfShow"].Width = ControlsAttribute.GV_WIDTH_SEEM; adgv.Columns["TotalCost"].HeaderText = ADGVText.Cost; adgv.Columns["TotalCost"].Width = ControlsAttribute.GV_WIDTH_NORMAL; adgv.Columns["ShowTypeId"].HeaderText = ADGVText.ShowType; adgv.Columns["ShowTypeId"].Width = ControlsAttribute.GV_WIDTH_NORMAL; lblNOProducts.Text = contractDetailVMs.Count + " sản phẩm"; } catch (Exception ex) { throw; } finally { _contractItemService = null; } }
private void UpdateContractDetailTotalCost() { try { _contractDetailService = new ContractItemService(); ContractDetailUpdateVM result = _contractDetailService.UpdateContractDetailCost(model.Id); txtTotalCost.Text = Utilities.DoubleMoneyToText(result.Cost); txtNumberOfShow.Text = result.NumberOfShow.ToString(); Logging.LogBusiness(string.Format("{0} {1} {2}", Common.Session.GetUserName(), Common.Constants.LogAction.Update, "giá tiền sản phẩm thuộc hợp đồng mã " + model.ContractCode), Common.Constants.BusinessLogType.Update); } catch (Exception) { throw; } finally { _contractDetailService = null; } }
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 btnPrint_Click(object sender, EventArgs e) { try { string contracCode = cboContractCode.SelectedValue.ToString(); string productName = cboProduct.SelectedValue.ToString(); if (!string.IsNullOrWhiteSpace(contracCode) && !string.IsNullOrWhiteSpace(productName)) { ContractItem contractItem = new ContractItemService().GetByContractCodeAndProductName(contracCode, productName); if (contractItem != null) { int contractDetailId = contractItem.Id; string cdProductName = contractItem.FileName; string exeFolder = Application.StartupPath; string reportPath = Path.Combine(exeFolder, @"Reports\ShowCommitmentReport.rdlc"); // using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ATVEntities"].ConnectionString)) { SqlDataAdapter da = null; try { string query = "SELECT ProductName, TimeSlot, ShowTime, TimeSlotCode, [1] as D1,[2] as D2,[3] as D3,[4] as D4,[5] as D5," + "[6] as D6,[7] as D7,[8] as D8,[9] as D9,[10] as D10, [11] as D11,[12] as D12,[13] as D13,[14] as D14,[15] as D15," + "[16] as D16,[17] as D17,[18] as D18,[19] as D19,[20] as D20,[21] as D21,[22] as D22,[23] as D23,[24] as D24, [25] as D25, " + "[26] as D26, [27] as D27, [28] as D28, [29] as D29, [30] as D30, [31] as D31, Qty " + "FROM" + "(" + "SELECT ProductName, TimeSlot, ShowTime, TimeSlotCode, " + "CAST(DAY(ShowDate) AS VARCHAR(4)) AS ShowDay, Quantity " + "FROM dbo.ProductScheduleShow p1 " + "WHERE p1.ProductName = @productName " + "AND YEAR(p1.ShowDate) = @rptYear " + "AND MONTH(p1.ShowDate) = @rptMonth " + "AND ContractDetailId = @contractDetailId" + ") AS ts LEFT JOIN( " + "SELECT ProductName as ProductName1, TimeSlotCode as TimeSlotCode1, SUM(Quantity) as Qty " + "FROM dbo.ProductScheduleShow p1 " + "WHERE p1.ProductName = @productName " + "AND YEAR(p1.ShowDate) = @rptYear " + "AND MONTH(p1.ShowDate) = @rptMonth " + "AND ContractDetailId = @contractDetailId " + "GROUP BY ProductName, Quantity, ShowTime, TimeSlotCode) as nu on ts.ProductName = nu.ProductName1 AND ts.TimeSlotCode = nu.TimeSlotCode1 " + "PIVOT " + "( " + "count(Quantity) " + "FOR ShowDay IN ( [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24], [25], [26], [27], [28], [29], [30], [31]) " + ") AS pvt"; var cmd = new SqlCommand(query, con); cmd.Parameters.Add(new SqlParameter("@rptYear", this.dtpMonth.Value.Year)); cmd.Parameters.Add(new SqlParameter("@rptMonth", this.dtpMonth.Value.Month)); cmd.Parameters.Add(new SqlParameter("@contractDetailId", contractDetailId)); cmd.Parameters.Add(new SqlParameter("@productName", cdProductName)); da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); var firstDayOfMonth = new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 1); var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); List <ViewModel.ShowCommitmentRM> commitments = Utilities.ConvertDataTable <ViewModel.ShowCommitmentRM>(dt); List <ViewModel.SCommitmentMRM> reportData = new List <ViewModel.SCommitmentMRM>(); foreach (var cm in commitments) { ViewModel.SCommitmentMRM sc = new ViewModel.SCommitmentMRM() { ShowTime = cm.ShowTime, TimeSlot = cm.TimeSlot, TimeSlotCode = cm.TimeSlotCode, Qty = cm.Qty, D1 = cm.D1 == 0 ? "" : cm.D1 + "", D2 = cm.D2 == 0 ? "" : cm.D2 + "", D3 = cm.D3 == 0 ? "" : cm.D3 + "", D4 = cm.D4 == 0 ? "" : cm.D4 + "", D5 = cm.D5 == 0 ? "" : cm.D5 + "", D6 = cm.D6 == 0 ? "" : cm.D6 + "", D7 = cm.D7 == 0 ? "" : cm.D7 + "", D8 = cm.D8 == 0 ? "" : cm.D8 + "", D9 = cm.D9 == 0 ? "" : cm.D9 + "", D10 = cm.D10 == 0 ? "" : cm.D10 + "", D11 = cm.D11 == 0 ? "" : cm.D11 + "", D12 = cm.D12 == 0 ? "" : cm.D12 + "", D13 = cm.D13 == 0 ? "" : cm.D13 + "", D14 = cm.D14 == 0 ? "" : cm.D14 + "", D15 = cm.D15 == 0 ? "" : cm.D15 + "", D16 = cm.D16 == 0 ? "" : cm.D16 + "", D17 = cm.D17 == 0 ? "" : cm.D17 + "", D18 = cm.D18 == 0 ? "" : cm.D18 + "", D19 = cm.D19 == 0 ? "" : cm.D19 + "", D20 = cm.D20 == 0 ? "" : cm.D20 + "", D21 = cm.D21 == 0 ? "" : cm.D21 + "", D22 = cm.D22 == 0 ? "" : cm.D22 + "", D23 = cm.D23 == 0 ? "" : cm.D23 + "", D24 = cm.D24 == 0 ? "" : cm.D24 + "", D25 = cm.D25 == 0 ? "" : cm.D25 + "", D26 = cm.D26 == 0 ? "" : cm.D26 + "", D27 = cm.D27 == 0 ? "" : cm.D27 + "", D28 = cm.D28 == 0 ? "" : cm.D28 + "", D29 = cm.D29 == 0 ? "" : cm.D29 + "", D30 = cm.D30 == 0 ? "" : cm.D30 + "", D31 = cm.D31 == 0 ? "" : cm.D31 + "", }; reportData.Add(sc); } ReportParameterCollection reportParameters = new ReportParameterCollection(); reportParameters.Add(new ReportParameter("strDate", this.dtpMonth.Value.Month + "/" + this.dtpMonth.Value.Year)); reportParameters.Add(new ReportParameter("strProductName", contractItem.ProductName)); reportParameters.Add(new ReportParameter("strFileName", contractItem.FileName)); reportParameters.Add(new ReportParameter("strLength", contractItem.DurationSecond + " giây")); reportParameters.Add(new ReportParameter("strFromToDate", string.Format("{0} đến {1}", firstDayOfMonth.ToShortDateString(), lastDayOfMonth.ToShortDateString()))); reportParameters.Add(new ReportParameter("intMaxDate", lastDayOfMonth.Day + "")); rptViewer.LocalReport.ReportPath = reportPath; rptViewer.LocalReport.DataSources.Clear(); rptViewer.LocalReport.SetParameters(reportParameters); rptViewer.LocalReport.DataSources.Add(new ReportDataSource("dsShowCommitment", reportData.AsEnumerable())); rptViewer.RefreshReport(); Logging.LogBusiness(string.Format("{0} {1} {2}", Common.Session.GetUserName(), Common.Constants.LogAction.ExportData, "chứng nhận phát sóng của khách hàng " + cboCustomer.SelectedValue.ToString() + " mã hợp đồng " + cboContractCode.SelectedValue.ToString() + " sản phẩm " + cboProduct.SelectedValue.ToString() + " trong " + this.dtpMonth.Value.Month + "/" + this.dtpMonth.Value.Year), Common.Constants.BusinessLogType.ExportData); } catch (Exception ex) { throw; } finally { if (da != null) { da.Dispose(); } } }; } } } catch (Exception ex) { throw; } }
private void btnPrint_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(txtPhone.Text) || string.IsNullOrWhiteSpace(txtSendTo.Text)) { Utilities.ShowMessage("Nhập đầy đủ các trường để tiếp tục"); return; } string contractCode = cboContractCode.SelectedValue.ToString(); string productName = cboProduct.SelectedValue.ToString(); if (!string.IsNullOrWhiteSpace(contractCode) && !string.IsNullOrWhiteSpace(productName)) { Contract contract = new ContractService().GetByCode(contractCode); ContractItem contractItem = new ContractItemService().GetByContractCodeAndProductName(contractCode, productName); if (contractItem != null) { Customer customer = new CustomerService().GetByCode(contract.CustomerCode); int contractDetailId = contractItem.Id; string cdProductName = contractItem.FileName; string exeFolder = Application.StartupPath; string reportPath = Path.Combine(exeFolder, @"Reports\InputScheduleReport.rdlc"); // using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ATVEntities"].ConnectionString)) { SqlDataAdapter da = null; try { string query = "SELECT ProductName, TimeSlot, ShowTime, TimeSlotCode, Cost, TotalCost, [1] as D1,[2] as D2,[3] as D3,[4] as D4,[5] as D5," + "[6] as D6,[7] as D7,[8] as D8,[9] as D9,[10] as D10, [11] as D11,[12] as D12,[13] as D13,[14] as D14,[15] as D15," + "[16] as D16,[17] as D17,[18] as D18,[19] as D19,[20] as D20,[21] as D21,[22] as D22,[23] as D23,[24] as D24, [25] as D25, " + "[26] as D26, [27] as D27, [28] as D28, [29] as D29, [30] as D30, [31] as D31, Qty " + "FROM" + "(" + "SELECT ProductName, TimeSlot, ShowTime, TimeSlotCode, Cost, TotalCost," + "CAST(DAY(ShowDate) AS VARCHAR(4)) AS ShowDay, Quantity " + "FROM dbo.ProductScheduleShow p1 " + "WHERE p1.ProductName = @productName " + "AND YEAR(p1.ShowDate) = @rptYear " + "AND MONTH(p1.ShowDate) = @rptMonth " + "AND ContractDetailId = @contractDetailId" + ") AS ts LEFT JOIN( " + "SELECT ProductName as ProductName1, TimeSlotCode as TimeSlotCode1, SUM(Quantity) as Qty " + "FROM dbo.ProductScheduleShow p1 " + "WHERE p1.ProductName = @productName " + "AND YEAR(p1.ShowDate) = @rptYear " + "AND MONTH(p1.ShowDate) = @rptMonth " + "AND ContractDetailId = @contractDetailId " + "GROUP BY ProductName, Quantity, ShowTime, TimeSlotCode) as nu on ts.ProductName = nu.ProductName1 AND ts.TimeSlotCode = nu.TimeSlotCode1 " + "PIVOT " + "( " + "count(Quantity) " + "FOR ShowDay IN ( [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24], [25], [26], [27], [28], [29], [30], [31]) " + ") AS pvt"; var cmd = new SqlCommand(query, con); cmd.Parameters.Add(new SqlParameter("@rptYear", this.dtpMonth.Value.Year)); cmd.Parameters.Add(new SqlParameter("@rptMonth", this.dtpMonth.Value.Month)); cmd.Parameters.Add(new SqlParameter("@contractDetailId", contractDetailId)); cmd.Parameters.Add(new SqlParameter("@productName", cdProductName)); da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); var firstDayOfMonth = new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 1); var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); List <ViewModel.InputScheduleRM> inputSchedules = Utilities.ConvertDataTable <ViewModel.InputScheduleRM>(dt); List <ViewModel.InputScheduleMRM> reportData = new List <ViewModel.InputScheduleMRM>(); foreach (var ins in inputSchedules) { ViewModel.InputScheduleMRM sc = new ViewModel.InputScheduleMRM() { ShowTime = ins.ShowTime, Cost = ins.Cost, TotalCost = ins.TotalCost, TimeSlot = ins.TimeSlot, TimeSlotCode = ins.TimeSlotCode, Qty = ins.Qty, D1 = ins.D1 == 0 ? "" : ins.D1 + "", D2 = ins.D2 == 0 ? "" : ins.D2 + "", D3 = ins.D3 == 0 ? "" : ins.D3 + "", D4 = ins.D4 == 0 ? "" : ins.D4 + "", D5 = ins.D5 == 0 ? "" : ins.D5 + "", D6 = ins.D6 == 0 ? "" : ins.D6 + "", D7 = ins.D7 == 0 ? "" : ins.D7 + "", D8 = ins.D8 == 0 ? "" : ins.D8 + "", D9 = ins.D9 == 0 ? "" : ins.D9 + "", D10 = ins.D10 == 0 ? "" : ins.D10 + "", D11 = ins.D11 == 0 ? "" : ins.D11 + "", D12 = ins.D12 == 0 ? "" : ins.D12 + "", D13 = ins.D13 == 0 ? "" : ins.D13 + "", D14 = ins.D14 == 0 ? "" : ins.D14 + "", D15 = ins.D15 == 0 ? "" : ins.D15 + "", D16 = ins.D16 == 0 ? "" : ins.D16 + "", D17 = ins.D17 == 0 ? "" : ins.D17 + "", D18 = ins.D18 == 0 ? "" : ins.D18 + "", D19 = ins.D19 == 0 ? "" : ins.D19 + "", D20 = ins.D20 == 0 ? "" : ins.D20 + "", D21 = ins.D21 == 0 ? "" : ins.D21 + "", D22 = ins.D22 == 0 ? "" : ins.D22 + "", D23 = ins.D23 == 0 ? "" : ins.D23 + "", D24 = ins.D24 == 0 ? "" : ins.D24 + "", D25 = ins.D25 == 0 ? "" : ins.D25 + "", D26 = ins.D26 == 0 ? "" : ins.D26 + "", D27 = ins.D27 == 0 ? "" : ins.D27 + "", D28 = ins.D28 == 0 ? "" : ins.D28 + "", D29 = ins.D29 == 0 ? "" : ins.D29 + "", D30 = ins.D30 == 0 ? "" : ins.D30 + "", D31 = ins.D31 == 0 ? "" : ins.D31 + "", }; reportData.Add(sc); } DateTime today = Utilities.GetServerDateTimeNow(); string strToday = Utilities.DateToFormatVNDate(today); ReportParameterCollection reportParameters = new ReportParameterCollection(); reportParameters.Add(new ReportParameter("str1Day", new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 1).DayOfWeek.ToString().Substring(0, 3))); reportParameters.Add(new ReportParameter("str2Day", new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 2).DayOfWeek.ToString().Substring(0, 3))); reportParameters.Add(new ReportParameter("str3day", new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 3).DayOfWeek.ToString().Substring(0, 3))); reportParameters.Add(new ReportParameter("str4day", new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 4).DayOfWeek.ToString().Substring(0, 3))); reportParameters.Add(new ReportParameter("str5day", new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 5).DayOfWeek.ToString().Substring(0, 3))); reportParameters.Add(new ReportParameter("str6day", new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 6).DayOfWeek.ToString().Substring(0, 3))); reportParameters.Add(new ReportParameter("str7day", new DateTime(this.dtpMonth.Value.Year, this.dtpMonth.Value.Month, 7).DayOfWeek.ToString().Substring(0, 3))); reportParameters.Add(new ReportParameter("strMonth", string.Format("{0}/{1}", this.dtpMonth.Value.Month, this.dtpMonth.Value.Year))); reportParameters.Add(new ReportParameter("strCustAddress", customer.Address)); reportParameters.Add(new ReportParameter("strCustPhone", customer.Phone1 + customer.Phone2)); reportParameters.Add(new ReportParameter("strCustFax", customer.Fax + " ")); reportParameters.Add(new ReportParameter("strCustEmail", customer.Email == null ? "" : customer.Email)); reportParameters.Add(new ReportParameter("strSendTo", txtSendTo.Text)); reportParameters.Add(new ReportParameter("strProductName", contractItem.ProductName)); reportParameters.Add(new ReportParameter("strFileName", contractItem.FileName)); reportParameters.Add(new ReportParameter("strLength", contractItem.DurationSecond + " s")); reportParameters.Add(new ReportParameter("strCreateDate", contractItem.CreateDate.Value.ToShortDateString())); reportParameters.Add(new ReportParameter("strReportDate", strToday)); reportParameters.Add(new ReportParameter("strReportBy", Common.Session.GetFullName())); reportParameters.Add(new ReportParameter("strReportByPhone", txtPhone.Text)); reportParameters.Add(new ReportParameter("intMaxDate", lastDayOfMonth.Day + "")); rptViewer.LocalReport.ReportPath = reportPath; rptViewer.LocalReport.DataSources.Clear(); rptViewer.LocalReport.SetParameters(reportParameters); rptViewer.LocalReport.DataSources.Add(new ReportDataSource("dsInputSchedule", reportData.AsEnumerable())); rptViewer.RefreshReport(); Logging.LogBusiness(string.Format("{0} {1} {2}", Common.Session.GetUserName(), Common.Constants.LogAction.ExportData, "lịch đăng ký quảng cáo của khách hàng " + cboCustomer.SelectedValue.ToString() + " mã hợp đồng " + cboContractCode.SelectedValue.ToString() + " sản phẩm " + cboProduct.SelectedValue.ToString()), Common.Constants.BusinessLogType.ExportData); } catch (Exception ex) { throw; } finally { if (da != null) { da.Dispose(); } } }; } } } catch (Exception ex) { throw; } }