public ActionResult GenerateMarksheet(int?id = null) { if (!Request.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } else { string user_id = User.Identity.GetUserId(); if (id == null) { ViewBag.ErrorMsg = "Invalid Request"; return(View("Error")); } else { hslc result = db.hslcs.Find(id); if (result != null) { requested_mark req_mark = db.requested_mark.Where(x => x.payment_status == "paid" && x.user_id == user_id && x.exam_result_id == result.id).FirstOrDefault(); if (req_mark == null) { ViewBag.ErrorMsg = "Please complete your payment."; return(View("Error")); } else { decimal?year = result.exm_year; if (year != null && year >= 2016) { //generate_2016_model(result); generate_marksheet(result); } else if (year >= 2010 && year <= 2015) { generate_2010_to_2015_model(result); } else if (year >= 2004 && year <= 2009) { generate_2004_to_2009_model(result); } else { ViewBag.ErrorMsg = "Under development." + year; return(View("Error")); } } } else { ViewBag.ErrorMsg = "Requested record does not exist in our database."; return(View("Error")); } } } return(RedirectToAction("GenerateInvoice")); }
public HttpResponseMessage Post(RequestModel req) { if (!ModelState.IsValid) { response = Request.CreateResponse(HttpStatusCode.BadRequest, "Bad Request: Improper Data Passed"); } else { hslc exam_result = db.hslcs.Where(x => x.roll == req.roll && x.exm_year.ToString() == req.exam_year && x.dob == req.dob).FirstOrDefault(); if (exam_result != null) { //int exam_res_id = db.Database.SqlQuery<int>("select id from students where roll_no='" + req.roll_no + "' and year='" + req.year + "' and dob='" + req.dob + "'").FirstOrDefault(); if (db.requested_mark.Any(m => m.exam_result_id == exam_result.id && m.user_id == req.user_id)) { response = Request.CreateResponse(HttpStatusCode.Conflict, "Duplicate request found! You have already requested the same. Please check in the request history."); } else { requested_mark requested_mark = new requested_mark(); requested_mark.request_date = DateTime.Now; requested_mark.payment_status = "unpaid"; requested_mark.exam_result_id = exam_result.id; requested_mark.user_id = req.user_id; requested_mark.id = generateRandomString(26); requested_mark.txn_id = null; db.requested_mark.Add(requested_mark); db.SaveChanges(); response = Request.CreateResponse(HttpStatusCode.OK, new { message = "Marksheet has been requested, please click proceed button for payment.", req_list = db.RequestHistories.Where(x => x.user_id == req.user_id && x.payment_status == "unpaid").ToList() }); } } else { response = Request.CreateResponse(HttpStatusCode.NotFound, "No record found for the input specification."); } } return(response); }
public void generate_2004_to_2009_model(hslc res) { string name = res.name.ToUpper(); string roll_no = res.roll.ToString(); string year = res.exm_year.ToString(); string dob = res.dob; //setting template pdf file path //string TemplateFile = "http://localhost:15059/Content/files/format_new.pdf"; string TemplateFile = Convert.ToString(ConfigurationManager.AppSettings["template_path"]); // open the reader PdfReader reader = new PdfReader(TemplateFile); iTextSharp.text.Rectangle size = reader.GetPageSizeWithRotation(1); //Pdf Stamper PdfStamper stamper = new PdfStamper(reader, Response.OutputStream); // Modifying the pdf content PdfContentByte cb = stamper.GetOverContent(1); // select the font properties BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.SetColorFill(BaseColor.DARK_GRAY); cb.SetFontAndSize(bf, 12); // write the text in the pdf content cb.BeginText(); // put the alignment and coordinates here cb.ShowTextAligned(Element.ALIGN_LEFT, name, 90, 647, 0); cb.EndText(); cb.BeginText(); // put the alignment and coordinates here cb.ShowTextAligned(Element.ALIGN_LEFT, roll_no, 120, 627, 0); cb.EndText(); cb.BeginText(); // put the alignment and coordinates here cb.ShowTextAligned(Element.ALIGN_LEFT, res.father_name.ToUpper(), 200, 608, 0); cb.EndText(); cb.BeginText(); // put the alignment and coordinates here cb.ShowTextAligned(Element.ALIGN_LEFT, res.mother_name.ToUpper(), 150, 589, 0); cb.EndText(); cb.BeginText(); // put the alignment and coordinates here cb.ShowTextAligned(2, dob, 180, 569, 0); cb.EndText(); cb.BeginText(); // put the alignment and coordinates here cb.ShowTextAligned(Element.ALIGN_LEFT, year, 80, 529, 0); // put the alignment and coordinates here cb.ShowTextAligned(Element.ALIGN_LEFT, res.school.ToUpper(), 170, 529, 0); cb.EndText(); PdfContentByte marks_print = stamper.GetOverContent(1); BaseFont basefont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.SetColorFill(BaseColor.DARK_GRAY); marks_print.SetFontAndSize(basefont, 11); //Getting subject wise marks //finding the list of subjects pescribed by the BoSEM for the year List <MarkModel> subs_inc_total = get_subjects_with_marks(res, true); //subjects included in grand total List <MarkModel> subs_not_inc_total = get_subjects_with_marks(res, false); //subjects not included in grand total int i = 0; //iteration int height = 460; //height int width = 40; //width for (; i < subs_inc_total.Count(); i++) { marks_print.BeginText(); // printing paper name marks_print.ShowTextAligned(Element.ALIGN_LEFT, (i + 1) + ". " + subs_inc_total.ElementAt(i).subject.ToUpper(), width + 10, height, 0); List <FieldModel> fields = subs_inc_total.ElementAt(i).fields; if (fields.Count() == 1) { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, fields.ElementAt(0).pass_mark.ToString(), width + 350, height, 0); marks_print.ShowTextAligned(Element.ALIGN_RIGHT, fields.ElementAt(0).full_mark.ToString(), width + 405, height, 0); marks_print.ShowTextAligned(Element.ALIGN_RIGHT, fields.ElementAt(0).scored_mark.ToString(), width + 490, height, 0); height = height - 15; } else { foreach (var field in fields) { height = height - 15; marks_print.ShowTextAligned(Element.ALIGN_LEFT, field.field_name, width + 20, height, 0); if (field.pass_mark == 0) { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, "---", width + 350, height, 0); } else { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, field.pass_mark.ToString(), width + 350, height, 0); } marks_print.ShowTextAligned(Element.ALIGN_RIGHT, field.full_mark.ToString(), width + 405, height, 0); if (field.field_name.Equals("TOTAL")) { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, field.scored_mark.ToString(), width + 490, height, 0); } else { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, field.scored_mark.ToString(), width + 460, height, 0); } } height = height - 15; } marks_print.EndText(); } /* PRINTING MARKSHEET */ // drawing a line /***************************/ height += 5; /*** Dash Line ***/ cb.MoveTo(45, height); cb.SetLineDash(5, 2, 0); cb.LineTo(size.Width - 45, height); cb.Stroke(); /*****************/ height -= 15; //Total without additional subject marks_print.BeginText(); marks_print.ShowTextAligned(Element.ALIGN_LEFT, "Total Without Additional Subject -", width + 10, height, 0); marks_print.ShowTextAligned(Element.ALIGN_RIGHT, res.total + "", width + 490, height, 0); marks_print.EndText(); /*** Dash Line ***/ height -= 10; cb.MoveTo(45, height); cb.SetLineDash(5, 2, 0); cb.LineTo(size.Width - 45, height); cb.Stroke(); /*****************/ /**** printing marks which are not included in total ****/ height = height - 16; for (int j = 0; j < subs_not_inc_total.Count(); j++) { MarkModel mark = subs_not_inc_total.ElementAt(j); marks_print.BeginText(); // printing paper name if (mark.sub_type.Trim().ToUpper().Equals("A") && res.addl_total != 0) { marks_print.ShowTextAligned(Element.ALIGN_LEFT, (++i) + ". " + mark.subject.ToUpper() + " AND EXCESS MARKS", width + 10, height, 0); } else { marks_print.ShowTextAligned(Element.ALIGN_LEFT, (++i) + ". " + mark.subject.ToUpper(), width + 10, height, 0); } List <FieldModel> fields = mark.fields; if (fields.Count() == 1) { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, fields.ElementAt(0).pass_mark.ToString(), width + 350, height, 0); marks_print.ShowTextAligned(Element.ALIGN_RIGHT, fields.ElementAt(0).full_mark.ToString(), width + 405, height, 0); marks_print.ShowTextAligned(Element.ALIGN_RIGHT, fields.ElementAt(0).scored_mark.ToString(), width + 490, height, 0); if (mark.sub_type.Trim().ToUpper().Equals("A")) { decimal?exceeding_mark = fields.ElementAt(0).scored_mark - fields.ElementAt(0).pass_mark; if (exceeding_mark > 0) { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, exceeding_mark.ToString(), width + 510, height, 0); } } height = height - 15; } else { foreach (var field in fields) { height = height - 15; marks_print.ShowTextAligned(Element.ALIGN_LEFT, field.field_name, width + 20, height, 0); marks_print.ShowTextAligned(Element.ALIGN_RIGHT, field.pass_mark.ToString(), width + 350, height, 0); marks_print.ShowTextAligned(Element.ALIGN_RIGHT, field.full_mark.ToString(), width + 405, height, 0); if (field.field_name.Equals("TOTAL")) { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, field.scored_mark.ToString(), width + 490, height, 0); } else { marks_print.ShowTextAligned(Element.ALIGN_RIGHT, field.scored_mark.ToString(), width + 460, height, 0); } } height = height - 15; } marks_print.EndText(); height = height + 5; if (mark.sub_type.Trim().ToUpper().Equals("A")) { /*** Dash Line ***/ cb.MoveTo(45, height); cb.SetLineDash(5, 2, 0); cb.LineTo(size.Width - 45, height); cb.Stroke(); /*****************/ height -= 15; marks_print.BeginText(); marks_print.ShowTextAligned(Element.ALIGN_LEFT, "GRAND TOTAL:", width + 60, height, 0); marks_print.ShowTextAligned(Element.ALIGN_RIGHT, res.gtotal + "", width + 490, height, 0); marks_print.EndText(); height -= 9; /*** Dash Line ***/ cb.MoveTo(45, height); cb.SetLineDash(5, 2, 0); cb.LineTo(size.Width - 45, height); cb.Stroke(); height -= 10; /*****************/ } height -= 7; } // print division string result = ""; switch (res.divi) { case 1: result = "1st"; break; case 2: result = "2nd"; break; case 3: result = "3rd"; break; case 4: result = "Simple Passed"; break; case 5: result = "Failed"; break; case 6: result = "Expelled"; break; } cb.BeginText(); cb.SetFontAndSize(bf, 12); // put the alignment and coordinates here cb.ShowTextAligned(Element.ALIGN_LEFT, result, 185, 507, 0); cb.EndText(); stamper.Close(); reader.Close(); Response.Buffer = true; Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=" + roll_no + year + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(stamper); Response.End(); }
public List <MarkModel> get_subjects_with_marks(hslc res, Boolean incl_in_tot) { /*incl_in_tot: subjects to be included in grand total or not*/ int include_in_total = incl_in_tot == true ? 1 : 0; //List<SubjectYearCombinations> l = db.SubjectYearCombinations List <MarkModel> mark_list = new List <MarkModel>(); string qry = "select S.name as sub_name,S.abbrevation as abbr, S.seq_cd,S.sub_type,C.id as sub_year_id " + "from SubjectYearCombinations as C inner join Subjects as S " + "on sub_id = S.id where C.year = " + res.exm_year + " and C.incl_in_total = " + include_in_total + " order by S.seq_cd "; List <Sub_taken> sub_taken_list = db.Database.SqlQuery <Sub_taken>(qry).ToList(); if (sub_taken_list == null || sub_taken_list.Count() == 0) { return(mark_list); } /*** opening database connection ****/ con.Open(); string query = "select * from hslc where id=" + res.id; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.Text; SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); /*******************************/ //for every subject taken by the student foreach (var item in sub_taken_list) { //Finding Subject fields List <SubjectFields> subjectFields = db.SubjectFields.Where(m => m.sub_year_id == item.sub_year_id).OrderBy(m => m.field_seq).ToList(); MarkModel mark = new MarkModel(); Type classType = res.GetType(); //PropertyInfo propertyInfo; string field_name; if (item.sub_type.ToUpper().Trim().Equals("A")) { //field_name = reader[item.abbr.Trim()].ToString(); field_name = reader["asub"].ToString(); mark.subject = get_sub_name(field_name); } else if (item.sub_type.ToUpper().Trim().Equals("F")) { //field_name = reader[item.abbr.Trim()].ToString(); field_name = reader["opt1"].ToString(); mark.subject = get_sub_name(field_name); } else { mark.subject = item.sub_name; } mark.sub_type = item.sub_type.Trim(); List <FieldModel> fields = new List <FieldModel>(); foreach (var field in subjectFields) { FieldModel fieldModel = new FieldModel(); fieldModel.field_name = field.field_meaning.Trim(); fieldModel.pass_mark = field.pass_mark; fieldModel.full_mark = field.full_mark; fieldModel.scored_mark = (reader[field.field_name.Trim()] != null)?Convert.ToDecimal(reader[field.field_name.Trim()]):0; fields.Add(fieldModel); } mark.fields = fields; mark_list.Add(mark); } con.Close();// closing connection return(mark_list); }