protected void btnAddPreset_Click(object sender, EventArgs e) { try { HttpPostedFile pf; pf = this.fulAddTemplate.PostedFile; if (pf.FileName == "") { this.ucMessanger1.ProcessMessage("No Template file has been selected.", Utilities.enMsgType.Err, "", null, true); return; } if (pf.ContentType != "application/pdf") { this.ucMessanger1.ProcessMessage("You have to select PDF file as a template.", Utilities.enMsgType.Err, "", null, true); return; } string fileName = Path.GetFileName(pf.FileName); int len = this.fulAddTemplate.PostedFile.ContentLength; byte[] template = new byte[len]; this.fulAddTemplate.PostedFile.InputStream.Read(template, 0, len); bizPreset biz = new bizPreset(); if (biz.ValidatePreset(Convert.ToInt32(Request.QueryString["aid"]), fileName, this.ddlAddDocumentType.SelectedValue) == false) { this.ucMessanger1.ProcessMessages(biz.MSGS, false); return; } if (biz.InsertPreset(Convert.ToInt32(Request.QueryString["aid"]), fileName, template, this.ddlAddDocumentType.SelectedValue) == true) { this.ucMessanger1.ProcessMessage("Preset has been succesfully inserted.", Utilities.enMsgType.OK, "", null, false); this.grvPresets.DataBind(); } else { this.ucMessanger1.ProcessMessage("An error has happened, please see the log.", Utilities.enMsgType.Err, "", null, true); } } catch (Exception ex) { bizLog.InsertExceptionLog(ex.Message, ex.StackTrace); Response.Redirect("~/ErrorPage.aspx", false); } }
protected void btnEdit_Click(object sender, EventArgs e) { if (UIValidation() == false) { return; } bizPreset biz = new bizPreset(); if (biz.ValidatePreset(Convert.ToInt32(this.ddlAssociations.SelectedValue), this.lblTemplateName.Text, this.ddlDocumentType.SelectedValue) == false) { this.ucMessanger1.ProcessMessages(biz.MSGS, true); return; } if (Session["pdf"] != null) { if (biz.UpdatePreset(Convert.ToInt32(this.Request.QueryString["pid"]), Convert.ToInt32(this.ddlAssociations.SelectedValue), this.lblTemplateName.Text, (byte[])Session["pdf"], this.ddlDocumentType.SelectedValue) == true) { this.ucMessanger1.ProcessMessages(biz.MSGS, true); } else { this.ucMessanger1.ProcessMessage("An error has happened, please see the log.", Utilities.enMsgType.Err, "", null, true); } } else { if (biz.UpdatePreset(Convert.ToInt32(this.Request.QueryString["pid"]), Convert.ToInt32(this.ddlAssociations.SelectedValue), this.lblTemplateName.Text, new byte[0], this.ddlDocumentType.SelectedValue) == true) { this.ucMessanger1.ProcessMessages(biz.MSGS, true); } else { this.ucMessanger1.ProcessMessage("An error has happened, please see the log.", Utilities.enMsgType.Err, "", null, true); } } }