protected void rptContracts_ItemCommand(object source, RepeaterCommandEventArgs e) { AgencyContract contract = Module.ContractGetById(Convert.ToInt32(e.CommandArgument)); switch (e.CommandName.ToLower()) { case "download": Response.Clear(); Response.ContentType = "application/octet-stream"; Response.AppendHeader("content-disposition", "attachment; filename=" + contract.FileName); Stream outputStream = Response.OutputStream; outputStream.Write(contract.ContractFile, 0, contract.ContractFile.Length); outputStream.Flush(); outputStream.Close(); Response.End(); break; case "edit": hiddenContractId.Value = e.CommandArgument.ToString(); txtContractName.Text = contract.ContractName; txtExpiredDate.Text = contract.ExpiredDate.ToString("dd/MM/yyyy"); break; } }
protected void btnSave_Click(object sender, EventArgs e) { AgencyContract contract; if (Request.QueryString["contractid"] != null) { contract = Module.ContractGetById(Convert.ToInt32(Request.QueryString["contractid"])); } else { contract = new AgencyContract(); contract.Agency = Module.AgencyGetById(Convert.ToInt32(Request.QueryString["agencyid"])); } contract.ContractName = txtName.Text; contract.ExpiredDate = DateTime.ParseExact(txtExpiredDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); if (fileUpload.HasFile) { contract.FilePath = FileHelper.Upload(fileUpload, "Contracts", false); contract.FileName = fileUpload.FileName; } contract.Received = chkReceived.Checked; contract.CreateDate = DateTime.Now; Module.SaveOrUpdate(contract); Page.ClientScript.RegisterStartupScript(typeof(AgencyContractEdit), "close", "window.opener.location = window.opener.location; window.close();", true); }
protected void btnIssueContract_Click(object sender, EventArgs e) { var agencyContract = new AgencyContract(); agencyContract.Agency = Agency; DateTime?contractValidFromDate = null; try { contractValidFromDate = DateTime.ParseExact(txtContractValidFromDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } catch { } agencyContract.ContractValidFromDate = contractValidFromDate; DateTime?contractValidToDate = null; try { contractValidToDate = DateTime.ParseExact(txtContractValidToDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } catch { } agencyContract.ContractValidToDate = contractValidToDate; agencyContract.ContractTemplateName = "Contract_" + Agency.Name + "_" + contractValidFromDate.Value.ToString("ddMMyyyy") + "_" + contractValidToDate.Value.ToString("ddMMyyyy"); agencyContract.ContractTemplatePath = "/Modules/Sails/Admin/ExportTemplates/Contract Lv1.doc"; AgencyViewBLL.AgencyContractSaveOrUpdate(agencyContract); Response.Redirect(Request.RawUrl); }
protected void btnSave_Click(object sender, EventArgs e) { AgencyContract contract; if (string.IsNullOrEmpty(hiddenContractId.Value)) { contract = new AgencyContract(); } else { contract = Module.ContractGetById(Convert.ToInt32(hiddenContractId.Value)); } contract.ContractName = txtContractName.Text; contract.ExpiredDate = DateTime.ParseExact(txtExpiredDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); if (fileUploadContract.HasFile) { contract.FileName = fileUploadContract.FileName; contract.ContractFile = fileUploadContract.FileBytes; } if (Request.QueryString["agencyid"] != null) { _agency = Module.AgencyGetById(Convert.ToInt32(Request.QueryString["agencyid"])); } contract.Agency = _agency; }
protected void rptContracts_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.DataItem is AgencyContract) { AgencyContract contract = (AgencyContract)e.Item.DataItem; Literal litExpiredDate = e.Item.FindControl("litExpiredDate") as Literal; if (litExpiredDate != null) { litExpiredDate.Text = contract.ExpiredDate.ToString("dd/MM/yyyy"); } } }
public void ExportQuotationToWord(AgencyContract agencyContract) { var doc = GetGeneratedQuotation(agencyContract); var m = new MemoryStream(); doc.Save(m, SaveFormat.Doc); Response.Clear(); Response.Buffer = true; Response.ContentType = "application/msword"; Response.AppendHeader("content-disposition", "attachment; filename=" + string.Format("{0}.doc", agencyContract.QuotationTemplateName)); Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length); Response.OutputStream.Flush(); Response.OutputStream.Close(); m.Close(); Response.End(); }
public Aspose.Words.Document GetGeneratedQuotation(AgencyContract agencyContract) { Quotation quotation = null; if (agencyContract != null) { //quotation = agencyContract.Quotation; } else { var selectedQuotation = -1; try { //selectedQuotation = Int32.Parse(ddlQuotationTemplate.SelectedValue); } catch { } quotation = AgencyViewBLL.QuotationGetById(selectedQuotation); } var doc = new Aspose.Words.Document(Server.MapPath("ExportTemplates/Quotation.doc")); var textValidFromDate = ""; try { textValidFromDate = quotation.ValidFrom.Value.ToString("dd/MM/yyyy"); } catch { } var textValidToDate = ""; try { textValidToDate = quotation.ValidTo.Value.ToString("dd/MM/yyyy"); } catch { } doc.Range.Replace(new Regex("(\\[ValidFromDate\\])"), textValidFromDate); doc.Range.Replace(new Regex("(\\[ValidToDate\\])"), textValidToDate); return(doc); }
public void AgencyContractSaveOrUpdate(AgencyContract agencyContract) { AgencyContractRepository.SaveOrUpdate(agencyContract); }
public Aspose.Words.Document GetGeneratedContract(AgencyContract agencyContract) { var templatePath = agencyContract.ContractTemplatePath; DateTime?validFromDate = null; try { validFromDate = DateTime.ParseExact(txtContractValidFromDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } catch (Exception) { } var validFromDay = validFromDate != null?validFromDate.Value.Day.ToString("#00") : ""; var validFrommonth = validFromDate != null ? (validFromDate.Value.Month + 1).ToString("#00") : ""; var validFromYear = validFromDate != null?validFromDate.Value.Year.ToString() : ""; var doc = new Aspose.Words.Document(Server.MapPath(templatePath)); var agencyName = ""; var agencyTradingName = ""; var agencyRepresentative = ""; var agencyRepresentativePosition = ""; var agencyContact = ""; var agencyContactEmail = ""; var agencyContactAddress = ""; var agencyContactPosition = ""; var agencyAddress = ""; var agencyPhone = ""; var agencyFax = ""; var agencyTaxCode = ""; var agencyWebsite = ""; try { agencyName = !String.IsNullOrEmpty(Agency.Name) ? Agency.Name : ""; } catch { } try { agencyTradingName = !String.IsNullOrEmpty(Agency.TradingName) ? Agency.TradingName : ""; } catch { } try { agencyRepresentative = !String.IsNullOrEmpty(Agency.Representative) ? Agency.Representative : ""; } catch { } try { agencyRepresentativePosition = !String.IsNullOrEmpty(Agency.RepresentativePosition) ? Agency.RepresentativePosition : ""; } catch { } try { agencyContact = !String.IsNullOrEmpty(Agency.Contact) ? Agency.Contact : ""; } catch { } try { agencyContactAddress = !String.IsNullOrEmpty(Agency.ContactAddress) ? Agency.ContactAddress : ""; } catch { } try { agencyContactPosition = !String.IsNullOrEmpty(Agency.ContactPosition) ? Agency.ContactPosition : ""; } catch { } try { agencyContactEmail = !String.IsNullOrEmpty(Agency.ContactEmail) ? Agency.ContactEmail : ""; } catch { } try { agencyAddress = !String.IsNullOrEmpty(Agency.Address) ? Agency.Address : ""; } catch { } try { agencyPhone = !String.IsNullOrEmpty(Agency.Phone) ? Agency.Phone : ""; } catch { } try { agencyFax = !String.IsNullOrEmpty(Agency.Fax) ? Agency.Fax : ""; } catch { } try { agencyTaxCode = !String.IsNullOrEmpty(Agency.TaxCode) ? Agency.TaxCode : ""; } catch { } DateTime?validToDate = null; try { validToDate = DateTime.ParseExact(txtContractValidToDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture); } catch { } var textValidToDate = ""; try { textValidToDate = validToDate.Value.ToString("dd/MM/yyyy"); } catch { } try { agencyWebsite = !String.IsNullOrEmpty(Agency.Website) ? Agency.Website : ""; } catch { } doc.Range.Replace(new Regex("(\\[ValidFromDay\\])"), validFromDay); doc.Range.Replace(new Regex("(\\[ValidFromMonth\\])"), validFrommonth); doc.Range.Replace(new Regex("(\\[ValidFromYear\\])"), validFromYear); doc.Range.Replace(new Regex("(\\[AgencyName\\])"), agencyName); doc.Range.Replace(new Regex("(\\[TradingName\\])"), agencyTradingName); doc.Range.Replace(new Regex("(\\[Representative\\])"), agencyRepresentative); doc.Range.Replace(new Regex("(\\[RepresentativePosition\\])"), agencyRepresentativePosition); doc.Range.Replace(new Regex("(\\[Contact\\])"), agencyContact); doc.Range.Replace(new Regex("(\\[ContactPosition\\])"), agencyContactPosition); doc.Range.Replace(new Regex("(\\[ContactAddress\\])"), agencyContactAddress); doc.Range.Replace(new Regex("(\\[ContactEmail\\])"), agencyContactEmail); doc.Range.Replace(new Regex("(\\[AgencyWebsite\\])"), agencyWebsite); doc.Range.Replace(new Regex("(\\[AgencyAddress\\])"), agencyAddress); doc.Range.Replace(new Regex("(\\[AgencyPhone\\])"), agencyPhone); doc.Range.Replace(new Regex("(\\[AgencyFax\\])"), agencyFax); doc.Range.Replace(new Regex("(\\[AgencyTaxCode\\])"), agencyTaxCode); doc.Range.Replace(new Regex("(\\[ValidToDate\\])"), textValidToDate); return(doc); }