Beispiel #1
0
        public ActionResult ReportLayout(string name)
        {
            ReportHeader      header = new ReportHeaderService(_unitOfWork).GetReportHeaderByName(name);
            List <ReportLine> lines  = _ReportLineService.GetReportLineList(header.ReportHeaderId).ToList();

            Dictionary <int, string> DefaultValues = TempData["ReportLayoutDefaultValues"] as Dictionary <int, string>;

            TempData["ReportLayoutDefaultValues"] = DefaultValues;
            foreach (var item in lines)
            {
                if (DefaultValues != null && DefaultValues.ContainsKey(item.ReportLineId))
                {
                    item.DefaultValue = DefaultValues[item.ReportLineId];
                }
            }

            ReportMasterViewModel vm = new ReportMasterViewModel();

            if (TempData["closeOnSelectOption"] != null)
            {
                vm.closeOnSelect = (bool)TempData["closeOnSelectOption"];
            }

            vm.ReportHeader   = header;
            vm.ReportLine     = lines;
            vm.ReportHeaderId = header.ReportHeaderId;

            return(View(vm));
        }
Beispiel #2
0
        public ActionResult PackingReportLayout(string name, int Id = 0)
        {
            ReportHeader      header = new ReportHeaderService(_unitOfWork).GetReportHeaderByName(name);
            List <ReportLine> lines  = _ReportLineService.GetReportLineList(header.ReportHeaderId).ToList();

            ReportMasterViewModel vm = new ReportMasterViewModel();

            vm.ReportHeader   = header;
            vm.ReportLine     = lines;
            vm.ReportHeaderId = header.ReportHeaderId;

            ViewBag.DataHeaderId = Id;
            return(View(vm));
        }
        public void Delete(ReasonViewModel vm, string UserName)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            var temp = Find(vm.id);

            LogList.Add(new LogTypeViewModel
            {
                ExObj = temp,
            });

            var line = _reportLineService.GetReportLineList(vm.id).ToList();


            foreach (var item in line)
            {
                LogList.Add(new LogTypeViewModel
                {
                    ExObj = item,
                });


                _reportLineService.Delete(item.ReportLineId);
            }

            Delete(temp);

            XElement Modifications = _modificationCheck.CheckChanges(LogList);

            _unitOfWork.Save();

            _logger.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = _DocumentTypeService.FindByName(TransactionDoctypeConstants.Report).DocumentTypeId,
                DocId           = temp.ReportHeaderId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                UserRemark      = vm.Reason,
                xEModifications = Modifications,
            }));
        }
Beispiel #4
0
        public ActionResult ReportPrint(FormCollection form, string ReportFileType)
        {
            var       SubReportDataList = new List <DataTable>();
            var       SubReportNameList = new List <string>();
            DataTable ReportData        = new DataTable();
            Dictionary <string, string> ReportFilters = new Dictionary <string, string>();
            StringBuilder queryString = new StringBuilder();

            string ReportHeaderId = (form["ReportHeaderId"].ToString());

            ReportHeader header = _ReportHeaderService.GetReportHeader(Convert.ToInt32(ReportHeaderId));
            List <ReportLineViewModel> lines = _ReportLineService.GetReportLineList(header.ReportHeaderId).ToList();


            if (string.IsNullOrEmpty(header.ReportSQL))
            {
                List <string> SubReportProcList = new List <string>();

                queryString.Append(header.SqlProc);

                using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand(queryString.ToString(), sqlConnection);

                    foreach (var item in lines)
                    {
                        if (item.SqlParameter != "" && item.SqlParameter != null)
                        {
                            if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                            {
                                if (item.SqlParameter == "@LoginSite")
                                {
                                    cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]);
                                }
                                //cmd.Parameters.AddWithValue(item.SqlParameter, 17);
                                else if (item.SqlParameter == "@LoginDivision")
                                {
                                    cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]);
                                }
                            }
                            else if (item.FieldName == "Site" && form[item.FieldName].ToString() == "")
                            {
                                cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]);
                            }

                            else if (item.FieldName == "Division" && form[item.FieldName].ToString() == "")
                            {
                                cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]);
                            }

                            else
                            {
                                if (form[item.FieldName].ToString() != "")
                                {
                                    if (item.DataType == "Date")
                                    {
                                        cmd.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? String.Format("{0:MMMM dd yyyy}", form[item.FieldName].ToString()) : "Null"));
                                    }
                                    else
                                    {
                                        cmd.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? form[item.FieldName].ToString() : "Null"));
                                    }
                                }
                            }
                        }
                    }


                    cmd.CommandTimeout = 200;
                    SqlDataAdapter sqlDataAapter = new SqlDataAdapter(cmd);
                    sqlDataAapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                    sqlDataAapter.Fill(ReportData);


                    if (ReportData.Rows.Count > 0)
                    {
                        if (ReportData.Columns.Contains("SubReportProcList"))
                        {
                            SubReportProcList.Add(ReportData.Rows[0]["SubReportProcList"].ToString());
                        }


                        DataTable SubRepData = new DataTable();
                        String    SubReportProc;

                        if (SubReportProcList != null)
                        {
                            if (SubReportProcList.Count > 0)
                            {
                                SubRepData = ReportData.Copy();

                                SqlConnection Con = new SqlConnection(connectionString);

                                while (SubRepData.Rows.Count > 0 && SubRepData.Columns.Contains("SubReportProcList"))
                                {
                                    SubReportProc = SubRepData.Rows[0]["SubReportProcList"].ToString();

                                    if (SubReportProc != "")
                                    {
                                        String         query          = "Web." + SubReportProc;
                                        SqlDataAdapter sqlDataAapter1 = new SqlDataAdapter(query.ToString(), Con);
                                        sqlDataAapter1.SelectCommand.CommandTimeout = 200;
                                        SubRepData.Reset();

                                        sqlDataAapter1.Fill(SubRepData);

                                        DataTable SubDataTable = new DataTable();
                                        SubDataTable = SubRepData.Copy();

                                        string SubRepName = "";
                                        if (SubDataTable.Rows.Count > 0)
                                        {
                                            SubReportDataList.Add(SubDataTable);
                                            SubRepName = (string)SubDataTable.Rows[0]["ReportName"];
                                            SubReportNameList.Add(SubRepName);
                                        }
                                        SubDataTable.Dispose();
                                    }
                                    else
                                    {
                                        //SubRepData = null;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                if (ReportData.Rows.Count > 0)
                {
                    var Paralist = new List <string>();

                    foreach (var item in lines)
                    {
                        if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                        {
                        }
                        else
                        {
                            if (item.SqlParameter != "" && item.SqlParameter != null && form[item.FieldName].ToString() != "")
                            {
                                if (item.DataType == "Date")
                                {
                                    if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                                    }
                                }
                                else if (item.DataType == "Single Select")
                                {
                                    if (!string.IsNullOrEmpty(item.ListItem))
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                    }
                                    else if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                                    }
                                }
                                //else if (item.DataType == "Constant Value")
                                //{

                                //    //if (!string.IsNullOrEmpty(form[item.FieldName].ToString())) { Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); }
                                //}

                                else if (item.DataType == "Multi Select")
                                {
                                    if (form[item.FieldName].ToString() != "")
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                                    }
                                }
                                else
                                {
                                    if (form[item.FieldName].ToString() != "")
                                    {
                                        Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                                    }
                                }
                            }
                        }
                    }

                    string mimtype;
                    ReportGenerateService c = new ReportGenerateService();
                    byte[] BAR;
                    //BAR = c.ReportGenerate(ReportData, out mimtype, ReportFileType, Paralist, SubReportDataList);
                    BAR = c.ReportGenerate(ReportData, out mimtype, ReportFileType, Paralist, SubReportDataList, null, SubReportNameList, User.Identity.Name);

                    XElement s    = new XElement(CustomStringOp.CleanCode(header.ReportName));
                    XElement Name = new XElement("Filters");
                    foreach (var Rec in ReportFilters)
                    {
                        Name.Add(new XElement(CustomStringOp.CleanCode(Rec.Key), Rec.Value));
                    }
                    s.Add(Name);

                    _logger.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = _documentTypeService.Find(TransactionDoctypeConstants.Report).DocumentTypeId,
                        DocId           = header.ReportHeaderId,
                        ActivityType    = (int)ActivityTypeContants.Report,
                        xEModifications = s,
                    }));

                    if (BAR.Length == 1)
                    {
                        ViewBag.Message = "Report Name is not define.";
                        return(View("Close"));
                    }
                    else if (BAR.Length == 2)
                    {
                        ViewBag.Message = "Report Title is not define.";
                        return(View("Close"));
                    }
                    else
                    {
                        //if (mimtype != "application/pdf")
                        if (mimtype == "application/vnd.ms-excel")
                        {
                            return(File(BAR, mimtype, header.ReportName + ".xls"));
                        }
                        else
                        {
                            return(File(BAR, mimtype));
                        }
                    }
                }

                else
                {
                    ViewBag.Message = "No Record to Print.";
                    return(View("Close"));
                }
            }

            else
            {
                List <ReportParameter> Params = new List <ReportParameter>();
                string ReportName             = "";

                foreach (var item in lines)
                {
                    if (item.SqlParameter != "" && item.SqlParameter != null)
                    {
                        if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                        {
                            if (item.SqlParameter == "@LoginSite")
                            {
                                ReportParameter Param = new ReportParameter();
                                Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                                Param.Values.Add(Convert.ToString(System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]));

                                Params.Add(Param);
                            }
                            else if (item.SqlParameter == "@LoginDivision")
                            {
                                ReportParameter Param = new ReportParameter();
                                Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                                Param.Values.Add(Convert.ToString(System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]));

                                Params.Add(Param);
                            }
                        }
                        else if (item.FieldName == "Site" && form[item.FieldName].ToString() == "")
                        {
                            ReportParameter Param = new ReportParameter();
                            Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                            Param.Values.Add(Convert.ToString(System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]));

                            Params.Add(Param);
                        }

                        else if (item.FieldName == "Division" && form[item.FieldName].ToString() == "")
                        {
                            ReportParameter Param = new ReportParameter();
                            Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                            Param.Values.Add(Convert.ToString(System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]));

                            Params.Add(Param);
                        }

                        else
                        {
                            if (form[item.FieldName].ToString() != "")
                            {
                                if (item.DataType == "Date")
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                                    Param.Values.Add((form[item.FieldName].ToString() != "" ? String.Format("{0:MMMM dd yyyy}", form[item.FieldName].ToString()) : "Null"));

                                    Params.Add(Param);
                                }
                                else
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = CustomStringOp.CleanCode(item.SqlParameter);
                                    Param.Values.Add((form[item.FieldName].ToString() != "" ? form[item.FieldName].ToString() : "Null"));

                                    Params.Add(Param);
                                }
                            }
                        }
                    }
                }



                int i = 0;
                foreach (var item in lines)
                {
                    if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                    {
                    }
                    else
                    {
                        if (item.SqlParameter != "" && item.SqlParameter != null && form[item.FieldName].ToString() != "")
                        {
                            if (item.DataType == "Date")
                            {
                                if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                    Params.Add(Param);

                                    ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                                }
                            }
                            else if (item.DataType == "Single Select")
                            {
                                if (!string.IsNullOrEmpty(item.ListItem) && !string.IsNullOrEmpty(form[item.FieldName]))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                    Params.Add(Param);
                                }
                                else if (!string.IsNullOrEmpty(form[item.FieldName].ToString()) && !string.IsNullOrEmpty(form[item.FieldName + "Names"]))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString());
                                    Params.Add(Param);

                                    ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                                }
                            }

                            else if (item.DataType == "Multi Select")
                            {
                                if (form[item.FieldName].ToString() != "" && !string.IsNullOrEmpty(form[item.FieldName + "Names"]))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString());
                                    Params.Add(Param);

                                    ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                                }
                            }
                            else
                            {
                                if (form[item.FieldName].ToString() != "" && !string.IsNullOrEmpty(form[item.FieldName]))
                                {
                                    ReportParameter Param = new ReportParameter();
                                    Param.Name = "FilterStr" + ++i;
                                    Param.Values.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                    Params.Add(Param);

                                    ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                                }
                            }
                        }
                    }
                }

                var uid = Guid.NewGuid();

                _reportUidValuesService.InsertRange(Params, uid);

                ReportName = _ReportHeaderService.GetReportNameFromProcedure(header.ReportSQL.Replace("REPORTUID", uid.ToString()));

                _reportUidValuesService.DeleteRange(uid);

                ReportParameter UserName = new ReportParameter();
                UserName.Name = "PrintedBy";
                UserName.Values.Add(User.Identity.Name);
                Params.Add(UserName);

                ReportParameter ConString = new ReportParameter();
                ConString.Name = "DatabaseConnectionString";
                ConString.Values.Add(connectionString);
                //Data Source=192.168.2.17;Initial Catalog=RUG;Integrated Security=false; User Id=sa; pwd=
                Params.Add(ConString);

                string mimtype;
                ReportGenerateService c = new ReportGenerateService();
                byte[] BAR;

                BAR = c.ReportGenerateCustom(out mimtype, ReportFileType, User.Identity.Name, Params, ReportName);

                XElement s    = new XElement(CustomStringOp.CleanCode(header.ReportName));
                XElement Name = new XElement("Filters");
                foreach (var Rec in ReportFilters)
                {
                    Name.Add(new XElement(CustomStringOp.CleanCode(Rec.Key), Rec.Value));
                }
                s.Add(Name);


                _logger.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = _documentTypeService.Find(TransactionDoctypeConstants.Report).DocumentTypeId,
                    DocId        = header.ReportHeaderId,
                    ActivityType = (int)ActivityTypeContants.Report,
                }));

                if (BAR.Length == 1)
                {
                    ViewBag.Message = "Report Name is not define.";
                    return(View("Close"));
                }
                else if (BAR.Length == 2)
                {
                    ViewBag.Message = "Report Title is not define.";
                    return(View("Close"));
                }
                else
                {
                    if (mimtype == "application/vnd.ms-excel")
                    {
                        return(File(BAR, mimtype, header.ReportName + ".xls"));
                    }
                    else
                    {
                        return(File(BAR, mimtype));
                    }
                }
            }
        }
        // GET: /ProductMaster/

        public JsonResult Index(int id)
        {
            var ReportLine = _ReportLineService.GetReportLineList(id).ToList();

            return(Json(ReportLine, JsonRequestBehavior.AllowGet));
        }
        public ActionResult ProcedureExcute(FormCollection form, string ReportFileType)
        {
            DataTable ReportData = new DataTable();
            Dictionary <string, string> ReportFilters = new Dictionary <string, string>();
            StringBuilder queryString = new StringBuilder();

            string ReportHeaderId = (form["ReportHeaderId"].ToString());

            ReportHeader      header = new ReportHeaderService(_unitOfWork).GetReportHeader(Convert.ToInt32(ReportHeaderId));
            List <ReportLine> lines  = _ReportLineService.GetReportLineList(header.ReportHeaderId).ToList();



            ApplicationDbContext Db = new ApplicationDbContext();

            queryString.Append(db.strSchemaName + "." + header.SqlProc);


            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand(queryString.ToString(), sqlConnection);

                foreach (var item in lines)
                {
                    if (item.SqlParameter != "" && item.SqlParameter != null)
                    {
                        if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                        {
                            if (item.SqlParameter == "@LoginSite")
                            {
                                cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]);
                            }
                            else if (item.SqlParameter == "@LoginDivision")
                            {
                                cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]);
                            }
                        }
                        else if (item.FieldName == "Site" && form[item.FieldName].ToString() == "")
                        {
                            cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]);
                        }

                        else if (item.FieldName == "Division" && form[item.FieldName].ToString() == "")
                        {
                            cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]);
                        }

                        else
                        {
                            if (form[item.FieldName].ToString() != "")
                            {
                                if (item.DataType == "Date")
                                {
                                    cmd.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? String.Format("{0:MMMM dd yyyy}", form[item.FieldName].ToString()) : "Null"));
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? form[item.FieldName].ToString() : "Null"));
                                }
                            }
                        }
                    }
                }


                cmd.CommandTimeout = 200;
                SqlDataAdapter sqlDataAapter = new SqlDataAdapter(cmd);
                sqlDataAapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                dsRep.EnforceConstraints = false;
                sqlDataAapter.Fill(ReportData);
            }

            var Paralist = new List <string>();

            foreach (var item in lines)
            {
                if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                {
                }
                else
                {
                    if (item.SqlParameter != "" && item.SqlParameter != null && form[item.FieldName].ToString() != "")
                    {
                        if (item.DataType == "Date")
                        {
                            if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                            {
                                Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                            }
                        }
                        else if (item.DataType == "Single Select")
                        {
                            if (!string.IsNullOrEmpty(item.ListItem))
                            {
                                Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                            }
                            else if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                            {
                                Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                            }
                        }
                        else if (item.DataType == "Multi Select")
                        {
                            if (form[item.FieldName].ToString() != "")
                            {
                                Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName + "Names"].ToString());
                            }
                        }
                        else
                        {
                            if (form[item.FieldName].ToString() != "")
                            {
                                Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString()); ReportFilters.Add(item.DisplayName, form[item.FieldName].ToString());
                            }
                        }
                    }
                }
            }

            XElement s    = new XElement(CustomStringOp.CleanCode(header.ReportName));
            XElement Name = new XElement("Filters");

            foreach (var Rec in ReportFilters)
            {
                Name.Add(new XElement(CustomStringOp.CleanCode(Rec.Key), Rec.Value));
            }
            s.Add(Name);


            LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(TransactionDoctypeConstants.Report).DocumentTypeId,
                DocId           = header.ReportHeaderId,
                Narration       = header.ReportName,
                ActivityType    = (int)ActivityTypeContants.Report,
                xEModifications = s,
            }));

            if (ReportData.Rows.Count > 0)
            {
                if (ReportData.Rows[0][0].ToString() == "Success")
                {
                    return(View("Success"));
                }
                else
                {
                    ViewBag.Error = ReportData.Rows[0][0].ToString();
                    return(View("Error"));
                }
            }

            else
            {
                ViewBag.Message = "No Record to Print.";
                return(View("Close"));
            }
        }
        public ActionResult ReportPrint(FormCollection form, string ReportFileType)
        {
            var       SubReportDataList = new List <DataTable>();
            DataTable ReportData        = new DataTable();



            StringBuilder queryString = new StringBuilder();

            string ReportHeaderId = (form["ReportHeaderId"].ToString());

            ReportHeader      header = new ReportHeaderService(_unitOfWork).GetReportHeader(Convert.ToInt32(ReportHeaderId));
            List <ReportLine> lines  = _ReportLineService.GetReportLineList(header.ReportHeaderId).ToList();

            List <string> SubReportProcList = new ReportHeaderService(_unitOfWork).GetSubReportProcList(Convert.ToInt32(ReportHeaderId));

            ApplicationDbContext Db = new ApplicationDbContext();

            queryString.Append(db.strSchemaName + "." + header.SqlProc);


            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand(queryString.ToString(), sqlConnection);

                foreach (var item in lines)
                {
                    if (item.SqlParameter != "" && item.SqlParameter != null)
                    {
                        if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                        {
                            if (item.SqlParameter == "@LoginSite")
                            {
                                //cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]);
                                cmd.Parameters.AddWithValue(item.SqlParameter, 17);
                            }
                            else if (item.SqlParameter == "@LoginDivision")
                            {
                                cmd.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]);
                            }
                        }
                        else
                        {
                            if (form[item.FieldName].ToString() != "")
                            {
                                if (item.DataType == "Date")
                                {
                                    cmd.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? String.Format("{0:MMMM dd yyyy}", form[item.FieldName].ToString()) : "Null"));
                                }
                                else
                                {
                                    cmd.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? form[item.FieldName].ToString() : "Null"));
                                }
                            }
                        }
                    }
                }


                SqlDataAdapter sqlDataAapter = new SqlDataAdapter(cmd);
                sqlDataAapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                dsRep.EnforceConstraints = false;
                sqlDataAapter.Fill(ReportData);



                if (SubReportProcList != null)
                {
                    if (SubReportProcList.Count > 0)
                    {
                        foreach (var SubReportProc in SubReportProcList)
                        {
                            SqlCommand cmd1           = new SqlCommand("[Web].[" + SubReportProc + "]", sqlConnection);
                            DataTable  SubReport1Data = new DataTable();

                            foreach (var item in lines)
                            {
                                if (item.SqlParameter != "" && item.SqlParameter != null)
                                {
                                    if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                                    {
                                        if (item.SqlParameter == "@LoginSite")
                                        {
                                            //cmd1.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginSiteId]);
                                            cmd.Parameters.AddWithValue(item.SqlParameter, 17);
                                        }
                                        else if (item.SqlParameter == "@LoginDivision")
                                        {
                                            cmd1.Parameters.AddWithValue(item.SqlParameter, (int)System.Web.HttpContext.Current.Session[SessionNameConstants.LoginDivisionId]);
                                        }
                                    }
                                    else
                                    {
                                        if (form[item.FieldName].ToString() != "")
                                        {
                                            if (item.DataType == "Date")
                                            {
                                                cmd1.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? String.Format("{0:MMMM dd yyyy}", form[item.FieldName].ToString()) : "Null"));
                                            }
                                            else
                                            {
                                                cmd1.Parameters.AddWithValue(item.SqlParameter, (form[item.FieldName].ToString() != "" ? String.Format("{0:MMMM dd yyyy}", form[item.FieldName].ToString()) : "Null"));
                                            }
                                        }
                                    }
                                }
                            }


                            SqlDataAdapter sqlDataAapter1 = new SqlDataAdapter(cmd1);
                            sqlDataAapter1.SelectCommand.CommandType = CommandType.StoredProcedure;
                            dsRep.EnforceConstraints = false;
                            sqlDataAapter1.Fill(SubReport1Data);

                            SubReportDataList.Add(SubReport1Data);

                            SubReport1Data = null;
                        }
                    }
                }
            }

            if (ReportData.Rows.Count > 0)
            {
                var Paralist = new List <string>();

                foreach (var item in lines)
                {
                    if (item.SqlParameter == "@LoginSite" || item.SqlParameter == "@LoginDivision")
                    {
                    }
                    else
                    {
                        if (item.SqlParameter != "" && item.SqlParameter != null && form[item.FieldName].ToString() != "")
                        {
                            if (item.DataType == "Date")
                            {
                                if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                                {
                                    Paralist.Add(item.DisplayName + " : " + form[item.FieldName].ToString());
                                }
                            }
                            else if (item.DataType == "Single Select")
                            {
                                if (!string.IsNullOrEmpty(form[item.FieldName].ToString()))
                                {
                                    Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString());
                                }
                            }
                            else if (item.DataType == "Constant Value")
                            {
                                //if (!string.IsNullOrEmpty(form[item.FieldName].ToString())) { Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString()); }
                            }

                            else
                            {
                                if (form[item.FieldName].ToString() != "")
                                {
                                    Paralist.Add(item.DisplayName + " : " + form[item.FieldName + "Names"].ToString());
                                }
                            }
                        }
                    }
                }

                string mimtype;
                ReportGenerateService c = new ReportGenerateService();
                byte[] BAR;
                BAR = c.ReportGenerate(ReportData, out mimtype, ReportFileType, Paralist, SubReportDataList);
                if (BAR.Length == 1)
                {
                    ViewBag.Message = "Report Name is not define.";
                    return(View("Close"));
                }
                else if (BAR.Length == 2)
                {
                    ViewBag.Message = "Report Title is not define.";
                    return(View("Close"));
                }
                else
                {
                    if (mimtype != "application/pdf")
                    {
                        return(File(BAR, mimtype, "Sale Order Report"));
                    }
                    else
                    {
                        return(File(BAR, mimtype));
                    }
                }
            }

            else
            {
                ViewBag.Message = "No Record to Print.";
                return(View("Close"));
            }
        }