Share


sewakdbDataContext swdb = new sewakdbDataContext();
tbl_AnnualReport tbannual = new tbl_AnnualReport();

try {

	#region Insert/Update data
	if (hfid.Value != string.Empty)	{

		tbannual = (from d in swdb.tbl_AnnualReports where d.AR_ID == Convert.ToInt32(hfid.Value) select d).FirstOrDefault();

		btnSubmit.Text = "Submit";

		msg = "Updated Successfully";

	} else {

		swdb.tbl_AnnualReports.InsertOnSubmit(tbannual);

		msg = "Inserted Successfully";

	}

	#endregion
	#region Entity
	tbannual.AR_DATE =Convert.ToDateTime (txtARDate.Text.Trim());
	tbannual.AR_HEADLINE = txtHeadline.Text.Trim();
	tbannual.entry_date = DateTime.Now;
	tbannual.ARCHIVE_STATUS = false;
	tbannual.DELSTATUS = false;
	if (FileUpload1.HasFile)
		tbannual.AR_COVER_IMAGE = uploadPhoto(ref FileUpload1);

	if(FileUpload2.HasFile)
		tbannual.AR_FILE = uploadDocument(ref FileUpload2);

	#endregion
	lblerr.Text = msg;
	lblerr.ForeColor = System.Drawing.Color.Green;
	swdb.SubmitChanges();
	//Reset

	reset();

	//Fill gridview
	_LoadGrid();

} catch (Exception ex) {

	lblerr.Text = ex.ToString();
	lblerr.ForeColor = System.Drawing.Color.Red;

}

Share