Exemple #1
0
        public ActionResult Generatereceipt(string MemberId, string MemberName, string actionType)
        {
            if (string.IsNullOrEmpty(MemberId) && string.IsNullOrEmpty(MemberName))
            {
                if (Request.HttpMethod == "GET")
                {
                    return(View());
                }
                else
                {
                    ModelState.AddModelError("Error", "Please enter Member Id or Member Name !");
                }
            }

            else
            {
                var Mainno = "";
                if ((MemberId != null) && (MemberId != ""))
                {
                    var x = br.ListofMemberNo(MemberId).ToList();
                    Mainno = x[0].MemID.ToString();
                }
                if ((MemberName != null) && (MemberName != ""))
                {
                    string[] Memno = MemberName.Split('|');
                    Mainno = Memno[3];
                }

                DataSet ds = br.GenerateRecepitDataset(Mainno);
                ds.Tables[0].TableName = "RecepitDataset";

                if (ds.Tables[0].Rows.Count > 0)
                {
                    var grid = new GridView();
                    grid.DataSource = ds.Tables[0];
                    grid.DataBind();

                    Response.ClearContent();
                    Response.Buffer = true;
                    Response.AddHeader("content-disposition", "attachment; filename=Receipt.xls");
                    Response.ContentType = "application/ms-excel";
                    Response.Charset     = "";
                    StringWriter   sw  = new StringWriter();
                    HtmlTextWriter htw = new HtmlTextWriter(sw);

                    grid.RenderControl(htw);

                    Response.Output.Write(sw.ToString());
                    Response.Flush();
                    Response.End();
                }
            }
            return(View());
        }