<td>
Upload Bank Statement/Passbook Statement</td>
<td>
<div id="Div_BankStatement" runat="server" Visible="false">
<asp:FileUpload ID="fld_BankStatement" CssClass="form-control" runat="server" />
<asp:CustomValidator ID="CustomValidator4" ForeColor="Red" runat="server"
Display="Dynamic" ValidationGroup="a" onservervalidate="CustomValidator4_ServerValidate">
</asp:CustomValidator>
</div>
<asp:LinkButton runat="server" ID="lb_BankStatement" OnClick="lb_BankStatement_Click" Text="Bank Statement" Visible="false"></asp:LinkButton>
<asp:Label ID="lbl_BankStatement_link" runat="server" Visible="false"></asp:Label>
</td>
aspx.cs code
protected void btn_submit_Click(object sender, EventArgs e)
{
string OfferLetter = null;
string SalarySlip = null;
string SalarySlip2 = null;
string SalarySlip3 = null;
string BankStatement = null;
if (fld_offerletter.HasFile)
{
string filename6 = Path.GetFileNameWithoutExtension(fld_offerletter.FileName);
string extension6 = Path.GetExtension(fld_offerletter.FileName);
string OfferLetterALL = filename6 + "_" + new Random().Next(7000).ToString() + extension6;
OfferLetter = "~/View/TrainingPartner/StudentData/OfferLetter/" + OfferLetterALL;
}
else
{
OfferLetter = Lbl_Offerletter_link.Text;
}
if (fld_salaryslip.HasFile)
{
string filename6 = Path.GetFileNameWithoutExtension(fld_salaryslip.FileName);
string extension6 = Path.GetExtension(fld_salaryslip.FileName);
string SalarySlipA = filename6 + "_" + new Random().Next(8000).ToString() + extension6;
SalarySlip = "~/View/TrainingPartner/StudentData/SalarySlip/" + SalarySlipA;
}
else
{
SalarySlip = null;
}
if (fld_salaryslip2.HasFile)
{
string filename7 = Path.GetFileNameWithoutExtension(fld_salaryslip2.FileName);
string extension7 = Path.GetExtension(fld_salaryslip2.FileName);
string SalarySlipB = filename7 + "_" + new Random().Next(8000).ToString() + extension7;
SalarySlip2 = "~/View/TrainingPartner/StudentData/SalarySlip/" + SalarySlipB;
}
else
{
SalarySlip2 = null;
}
if (fld_salaryslip3.HasFile)
{
string filename8 = Path.GetFileNameWithoutExtension(fld_salaryslip3.FileName);
string extension8 = Path.GetExtension(fld_salaryslip3.FileName);
string SalarySlipC = filename8 + "_" + new Random().Next(8000).ToString() + extension8;
SalarySlip3 = "~/View/TrainingPartner/StudentData/SalarySlip/" + SalarySlipC;
}
else
{
SalarySlip3 = null;
}
if (fld_BankStatement.HasFile)
{
string filename9 = Path.GetFileNameWithoutExtension(fld_BankStatement.FileName);
string extension9 = Path.GetExtension(fld_BankStatement.FileName);
string BankStatementAll = filename9 + "_" + new Random().Next(8000).ToString() + extension9;
BankStatement = "~/View/TrainingPartner/StudentData/BankStatement/" + BankStatementAll;
}
else
{
BankStatement = null;
}
if (ViewState["CSRF"] != null && Convert.ToString(ViewState["CSRF"]) == Session["randomno"].ToString())
{
if (Page.IsValid)
{
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@tpid",Session["trainingpartnercode"]!=null?Convert.ToString(Session["trainingpartnercode"]):null),
new SqlParameter("@studentregid",regid.Text.Length>0?regid.Text:null),
new SqlParameter("@compname",string.IsNullOrEmpty(txt_compname.Text)?null:txt_compname.Text.Trim()),
new SqlParameter("@compemail",string.IsNullOrEmpty(txt_email.Text)?null:Convert.ToString(txt_email.Text.Trim())),
new SqlParameter("@contactno",string.IsNullOrEmpty(txt_landphone.Text)?null:txt_landphone.Text.Trim()),
new SqlParameter("@compwebsite",string.IsNullOrEmpty(txt_website.Text)?null:txt_website.Text.Trim()),
new SqlParameter("@compaddress",!string.IsNullOrEmpty(txt_compaddress.Text.Trim())?txt_compaddress.Text.Trim():null),
new SqlParameter("@offerletter", OfferLetter),
new SqlParameter("@salaryslip",SalarySlip),
new SqlParameter("@jobdesc",string.IsNullOrEmpty(txt_jobdesc.Text)?null:txt_jobdesc.Text.Trim()),
new SqlParameter("@salaryslip2",SalarySlip2),
new SqlParameter("@salaryslip3",SalarySlip3),
new SqlParameter("@bankstatement",BankStatement),
};
int result = 0;
result = Luminious.DataAcessLayer.SqlHelper.ExecuteNonQuery(Luminious.Connection.Configuration.ConnectionString, "USP_MST_STU_PLACEMENT_TP_Insert", para);
if (result > 0)
{
if (fld_offerletter.HasFile)
{
fld_offerletter.SaveAs(MapPath(OfferLetter));
}
if (fld_salaryslip.HasFile)
{
fld_salaryslip.SaveAs(MapPath(SalarySlip));
}
if (fld_salaryslip2.HasFile)
{
fld_salaryslip2.SaveAs(MapPath(SalarySlip2));
}
if (fld_salaryslip3.HasFile)
{
fld_salaryslip3.SaveAs(MapPath(SalarySlip3));
}
if (fld_BankStatement.HasFile)
{
fld_BankStatement.SaveAs(MapPath(BankStatement));
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Student Placed Sucessfully');", true);
#region redirectbtmeta
HtmlMeta meta = new HtmlMeta();
meta.HttpEquiv = "Refresh";
meta.Content = "2;url=StudentList.aspx";
this.Page.Controls.Add(meta);
#endregion
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Error Occured');", true);
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
GC.SuppressFinalize(this);
CrossSiteRequestForgery();
CreateRandomHashing();
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Insufficient Information');", true);
}
}
else
{
CrossSiteRequestForgery();
}
//else
//{
// ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Insufficient Information');", true);
//}
}
protected void Page_Load(object sender, EventArgs e)
{
Page.Form.Attributes.Add("enctype", "multipart/form-data");
if (!Page.IsPostBack)
{
StudentPlacement obj1 = new StudentPlacement();
List<Placementtemp> o = new List<Placementtemp>();
Placementtemp em = new Placementtemp();
using (obj1)
{
em = obj1.PlacementView(string.IsNullOrEmpty(StudentRegid) ? null : StudentRegid)[0];
}
if (em.BankStatement == null)
{
Div_BankStatement.Visible = true;
}
else
{
Div_BankStatement.Visible = false;
lb_BankStatement.Visible = true;
lbl_BankStatement_link.Text = em.SalarySlip3;
}
Div_BankStatement.Visible = true;
}
}
//see brackets may be less or more
protected void lb_salaryslip3_OnClick(object sender, EventArgs e)
{
string link = Lbl_SalarySlip3_link.Text;
Response.Redirect("" + link + "");
}
protected void CustomValidator4_ServerValidate(object source, ServerValidateEventArgs args)
{
if (fld_BankStatement.HasFile)
{
args.IsValid = true;
string fileextension = Path.GetExtension(fld_BankStatement.PostedFile.FileName);
string[] extension = { ".pdf", ".PDF" };
if (extension.Contains(fileextension))
{
if (fld_BankStatement.FileBytes.Length > 100000)
{
args.IsValid = false;
((CustomValidator)source).IsValid = false;
CustomValidator4.ErrorMessage = "File Size Cannot Exceed More Than 100 KB";
return;
}
else
{
args.IsValid = true;
}
}
else
{
args.IsValid = false;
((CustomValidator)source).IsValid = false;
CustomValidator4.ErrorMessage = "Invalid File Type";
return;
}
}
else
{
args.IsValid = true;
}
}
No comments:
Post a Comment