protected void ButtonClaimAttachment_Click(object sender, EventArgs e) { LabelError.Text = ""; bool hasError = false; PanelError.Visible = false; PanelErrorSpace.Visible = false; if (TextBoxDescription.Text.Length == 0) { LabelError.Text += "Claim Description is required.\n"; PanelError.Visible = true; PanelErrorSpace.Visible = true; hasError = true; } if (!FileClaimAttachment.HasFile) { LabelError.Text += "Attachment is required.\n"; PanelError.Visible = true; PanelErrorSpace.Visible = true; hasError = true; } if (hasError == false) { try { ClaimAttachment claimAttachment = new ClaimAttachment(); claimAttachment.Description = TextBoxDescription.Text; claimAttachment.Attachment = UploadAttachment(); claimAttachment.ClaimId = this.claimId; claimAttachment.ModifiedUser = this.Master.LoggedOnAccount; claimAttachment.Save(); BindClaimAttachmentList(); TextBoxDescription.Text = ""; } catch (System.Data.SqlClient.SqlException sqlEx) { LabelError.Text = ""; for (int i = 0; i < sqlEx.Errors.Count; i++) { LabelError.Text += (sqlEx.Errors[i].Message + "<br />"); } PanelError.Visible = true; PanelErrorSpace.Visible = true; } } }
protected void GridViewClaimAttachment_RowCommand(object sender, GridViewCommandEventArgs e) { try { switch (e.CommandName.ToLower()) { case "removeclaimattachment": { ClaimAttachment.DeleteClaimAttachmentByClaimAttachmentId(Convert.ToInt32(e.CommandArgument)); BindClaimAttachmentList(); break; } case "viewclaimattachment": { ClaimAttachment claimAttachment = ClaimAttachment.GetClaimAttachmentByClaimAttachmentId(Convert.ToInt32(e.CommandArgument)); Response.Clear(); Response.ContentType = "image/jpg"; Response.AppendHeader("Content-Disposition", "attachment; filename=ClaimAttachment.jpg"); Response.TransmitFile(claimAttachment.Attachment); Response.End(); break; } } } catch (System.Data.SqlClient.SqlException sqlEx) { LabelError.Text = ""; for (int i = 0; i < sqlEx.Errors.Count; i++) { LabelError.Text += (sqlEx.Errors[i].Message + "<br />"); } PanelError.Visible = true; } }
private void BindClaimAttachmentList() { GridViewClaimAttachment.DataSource = ClaimAttachment.GetClaimAttachmentListByClaimId(this.claimId); GridViewClaimAttachment.DataBind(); }