protected void rptHistory_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.DataItem is AgencyHistory) { AgencyHistory history = (AgencyHistory)e.Item.DataItem; Literal litSale = e.Item.FindControl("litSale") as Literal; if (litSale != null) { if (history.Sale != null) { litSale.Text = history.Sale.FullName; } else { litSale.Text = "Unbound Sales"; } } Literal litSaleStart = e.Item.FindControl("litSaleStart") as Literal; if (litSaleStart != null) { litSaleStart.Text = history.ApplyFrom.ToString("dd/MM/yyyy"); } if (history.ApplyFrom == _current) { HtmlTableRow trLine = e.Item.FindControl("trLine") as HtmlTableRow; if (trLine != null) { trLine.Attributes.Add("style", "font-weight: bold; color: red;"); } } } }
protected void buttonSave_Click(object sender, EventArgs e) { bool isAddnew = false; if (Request.QueryString["AgencyId"] != null) { _agency = Module.AgencyGetById(Convert.ToInt32(Request.QueryString["AgencyId"])); } else { _agency = new Agency(); isAddnew = true; } _agency.Name = textBoxName.Text; _agency.Phone = txtPhone.Text; _agency.Address = txtAddress.Text; _agency.TradingName = txtTradingName.Text; _agency.Representative = txtRepresentative.Text; _agency.RepresentativePosition = txtRepresentativePosition.Text; _agency.Contact = txtContact.Text; _agency.ContactAddress = txtContactAddress.Text; _agency.ContactEmail = txtContactEmail.Text; _agency.ContactPosition = txtContactPosition.Text; _agency.Website = txtWebsite.Text; _agency.ContractAddress = txtContractAddress.Text; _agency.ContractPhone = txtContractPhone.Text; _agency.ContractTaxCode = txtContractTaxCode.Text; if (ddlAgencyRoles.SelectedIndex != 0) { _agency.Role = Module.RoleGetById(Convert.ToInt32(ddlAgencyRoles.SelectedValue)); } else { _agency.Role = null; } if (!string.IsNullOrWhiteSpace(ddlAgentLevel.SelectedValue)) { _agency.QAgentlevel = Module.GetById <QAgentLevel>(Convert.ToInt32(ddlAgentLevel.SelectedValue)); } _agency.Email = txtEmail.Text; _agency.TaxCode = txtTaxCode.Text; _agency.Description = txtDescription.Text; //_agency.ContractStatus = Convert.ToInt32(ddlContractStatus.SelectedValue); _agency.PaymentPeriod = (PaymentPeriod)Enum.Parse(typeof(PaymentPeriod), ddlPaymentPeriod.SelectedValue); User oldsale = _agency.Sale; DateTime?oldStart = _agency.SaleStart; if (!string.IsNullOrEmpty(txtSaleStart.Text)) { _agency.SaleStart = DateTime.ParseExact(txtSaleStart.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } else { _agency.SaleStart = null; } if (ddlSales.Items.Count > 0 && ddlSales.SelectedIndex > 0) { _agency.Sale = Module.UserGetById(Convert.ToInt32(ddlSales.SelectedValue)); } else { _agency.Sale = null; } if (_agency.Id <= 0) { _agency.CreatedBy = UserIdentity; _agency.CreatedDate = DateTime.Now; } else { _agency.ModifiedBy = UserIdentity; _agency.ModifiedDate = DateTime.Now; } if (ddlLocations.SelectedIndex > 0) { _agency.Location = Module.GetObject <AgencyLocation>(Convert.ToInt32(ddlLocations.SelectedValue)); } else { _agency.Location = null; } Module.SaveOrUpdate(_agency); //foreach (RepeaterItem item in rptCruises.Items) //{ // var hiddenCruiseId = item.FindControl("hiddenCruiseId") as HiddenField; // var ddlRoles = item.FindControl("ddlRoles") as DropDownList; // if (hiddenCruiseId != null && ddlRoles != null) // { // Cruise cruise = Module.CruiseGetById(Convert.ToInt32(hiddenCruiseId.Value)); // CruiseRole role = Module.GetCruiseRole(cruise, _agency); // role.Cruise = cruise; // role.Agency = _agency; // role.Role = Module.RoleGetById(Convert.ToInt32(ddlRoles.SelectedValue)); // Module.SaveOrUpdate(role); // } //} // Nếu chưa có lịch sử thì lưu lại if (_agency.History.Count == 0 && oldsale != null) { AgencyHistory history = new AgencyHistory(); history.Agency = _agency; history.Sale = oldsale; if (oldStart.HasValue) { history.ApplyFrom = oldStart.Value; } else { history.ApplyFrom = new DateTime(2000, 1, 1); } Module.SaveOrUpdate(history); } if ((oldsale != _agency.Sale || oldStart != _agency.SaleStart) && _agency.SaleStart != null) { // Khi có sự thay đổi về sale và ngày áp dụng thì lưu lại lịch sử // Nhưng nếu đã có ngày áp dụng này rồi thì lưu lại theo sale mới AgencyHistory history = null; foreach (AgencyHistory oldhis in _agency.History) { if (oldhis.ApplyFrom == _agency.SaleStart.Value) { history = oldhis; break; } } if (history == null) { history = new AgencyHistory(); } history.Agency = _agency; history.Sale = _agency.Sale; history.ApplyFrom = _agency.SaleStart.Value; Module.SaveOrUpdate(history); } if (isAddnew) { PageRedirect(string.Format("AgencyEdit.aspx?NodeId={0}&SectionId={1}&AgencyId={2}", Node.Id, Section.Id, _agency.Id)); } else { PageRedirect(string.Format("AgencyList.aspx?NodeId={0}&SectionId={1}", Node.Id, Section.Id)); } }