Beispiel #1
0
        public ActionResult ExportBinderAllotment(string startDate, string endDate)
        {
            List <BinderAllotQuantity> listBinderAllotQuantity = new List <BinderAllotQuantity>();

            try
            {
                StringBuilder strTableReport = new StringBuilder();
                StringBuilder strReport      = new StringBuilder();
                strReport = new StringBuilder();
                Int16     AccadYear     = Convert.ToInt16(GlobalSettings.oUserData.AcademicYearId);
                DataTable dtbinderallot = objDbTrx.GetBinderAllotmentQtyView(Convert.ToDateTime(startDate + " 00:00:00.000"), Convert.ToDateTime(endDate + " 23:59:59.999"), AccadYear);
                if (dtbinderallot.Rows.Count > 0)
                {
                    strReport.AppendLine("<tr>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >BINDER_ALLOT_CODE</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >BOOK_CODE</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >BinderName</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >LANGUAGE</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >BOOK_NAME</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >ALLOTMENT_DATE</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >TOT_QTY</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >LOT</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >REQ_QTY</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:#b3cbff;' >QTY_ISSUED</th>");
                    strReport.AppendLine("  <th style='text-align:left;background-color:b3cbff;' >STATUS</th>");

                    strReport.AppendLine("</tr>");
                    for (int iCnt = 0; iCnt < dtbinderallot.Rows.Count; iCnt++)
                    {
                        strReport.AppendLine("<tr>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["BINDER_ALLOT_CODE"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["BOOK_CODE"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["BinderName"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["LANGUAGE"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["BOOK_NAME"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["ALLOTMENT_DATE"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["TOT_QTY"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["LOT"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["REQ_QTY"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + dtbinderallot.Rows[iCnt]["QTY_ISSUED"].ToString() + "      </td>");
                        strReport.AppendLine("      <td> " + (dtbinderallot.Rows[iCnt]["STATUS"].ToString() == "0" ? "Draft" : "Confirmed") + "      </td>");
                        strReport.AppendLine("</tr>");
                    }
                    strTableReport.AppendLine("<table border='1'>");
                    strTableReport.AppendLine("          " + strReport.ToString());
                    strTableReport.AppendLine("</table>");

                    Response.Clear();
                    Response.Buffer      = true;
                    Response.ContentType = "application/vnd.ms-excel";
                    String FileName = "BinderAllotBooks" + DateTime.Now.Year.ToString() + "_" + DateTime.Now.ToString("dd-MMM-yyyy") + ".xls";

                    Response.AddHeader("Content-Disposition", "inline;filename=" + FileName);
                    String HTMLDataToExport = strTableReport.ToString();


                    Response.Write("<html><head><head>" +
                                   HTMLDataToExport.Replace("<BR>", "<br style='mso-data-placement:same-cell;'>")
                                   .Replace("<br>", "<br style='mso-data-placement:same-cell;'>")
                                   .Replace("<BR >", "<br style='mso-data-placement:same-cell;'>")
                                   .Replace("<BR />", "<br style='mso-data-placement:same-cell;'>")
                                   .Replace("<br />", "<br style='mso-data-placement:same-cell;'>")
                                   .Replace("<Br />", "<br style='mso-data-placement:same-cell;'>")
                                   .Replace("<Br>", "<br style='mso-data-placement:same-cell;'>")
                                   .Replace("<br >", "<br style='mso-data-placement:same-cell;'>") + "</html>");
                    Response.End();
                }
            }
            catch (Exception ex)
            {
                objDbTrx.SaveSystemErrorLog(ex, Request.UserHostAddress);
            }
            return(View());
        }