private JObject GetTicketsHistory(HttpContext context)
        {
            JObject responseJObj = new JObject();

            try
            {
                UDC.Ticket ticket = new UDC.Ticket();
                ticket.Mode      = context.Request["mode"] != null?Convert.ToInt32(context.Request["mode"]) : 0;;
                ticket.AccountId = accountId;
                //ticket.AgentId = agentId;
                ticket.RoleId = roleId;
                if (roleId == 1)
                {
                    ticket.AgentId         = agentId;
                    ticket.SelectedAgentId = agentId;
                }
                else
                {
                    ticket.AgentId         = agentId;
                    ticket.SelectedAgentId = context.Request["agentId"] != null?Convert.ToInt32(context.Request["agentId"]) : 0;
                }

                //ticket.SelectedAgentId = context.Request["agentId"] != null ? Convert.ToInt32(context.Request["agentId"]) : 0;
                ticket.Id = context.Request["ticketId"] != null?Convert.ToInt64(context.Request["ticketId"]) : 0;

                ticket.Subject     = context.Request["subject"];
                ticket.StatusIds   = context.Request["statusIds"];
                ticket.PriorityIds = context.Request["priorityIds"];
                ticket.TicketType  = context.Request["ticketType"] != null?Convert.ToInt32(context.Request["ticketType"]) : 0;

                ticket.OverDueType = context.Request["overDueType"] != null?Convert.ToInt32(context.Request["overDueType"]) : 0;

                ticket.DurationType = context.Request["durationType"] != null?Convert.ToInt32(context.Request["durationType"]) : 0;

                ticket.CustomerId = context.Request["customerId"] != null?Convert.ToInt32(context.Request["customerId"]) : 0;

                ticket.FromDate  = context.Request["fromDate"];
                ticket.ToDate    = context.Request["toDate"];
                ticket.PageIndex = Convert.ToInt32(context.Request["pageIndex"]);
                ticket.PageSize  = Convert.ToInt32(context.Request["pageSize"]);
                ticket.IsStarred = context.Request["isStarred"] != null?Convert.ToBoolean(Convert.ToInt16(context.Request["isStarred"])) : Convert.ToBoolean(Convert.ToInt16(0));   //Convert.ToBoolean(Convert.ToInt16(context.Request["isStarred"]));

                ticket.CategoryId = context.Request["CategoryId"] != "0" ? Convert.ToInt32(context.Request["CategoryId"]) : 0;
                Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
                responseJObj = ticketObj.GetTicketsHistory(MyConfig.MyConnectionString, ticket);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
            return(responseJObj);
        }
        public void DownloadTicketExcelReports_Click(object sender, EventArgs e)
        {
            DataSet responseDataSet = new DataSet();

            UDC.Ticket ticket = new UDC.Ticket();
            ticket.Mode = 1;

            if (roleId == 1)
            {
                ticket.AgentId         = agentId;
                ticket.SelectedAgentId = agentId;
            }
            else
            {
                ticket.AgentId         = agentId;
                ticket.SelectedAgentId = Convert.ToInt32(hdnAgentId.Value);
            }


            ticket.AccountId = accountId;
            ticket.RoleId    = roleId;
            ticket.Id        = hdnTicketId.Value != null?Convert.ToInt32(hdnTicketId.Value) : 0;

            ticket.Subject     = hdnTicketSubject.Value;
            ticket.StatusIds   = hdnTicketStatuses.Value;
            ticket.PriorityIds = hdnTicketPriorities.Value;
            ticket.TicketType  = hdnTicketType.Value != null?Convert.ToInt32(hdnTicketType.Value) : 0;

            ticket.OverDueType = hdnDueType.Value != null?Convert.ToInt32(hdnDueType.Value) : 0;

            ticket.DurationType = hdnDurationType.Value != null?Convert.ToInt32(hdnDurationType.Value) : 0;

            ticket.CustomerId = 0;
            ticket.FromDate   = hdnFromDate.Value;
            ticket.ToDate     = hdnToDate.Value;
            ticket.PageIndex  = Convert.ToInt32(hdnPageIndex.Value);
            ticket.PageSize   = Convert.ToInt32(hdnPageSize.Value);
            ticket.IsStarred  = Convert.ToBoolean(Convert.ToInt16(hdnIsStarred.Value));
            ticket.CategoryId = hdnCategoryId.Value != "0" ? Convert.ToInt32(hdnCategoryId.Value) : 0;
            Press3.BusinessRulesLayer.Ticket ticketObj = new Press3.BusinessRulesLayer.Ticket();
            responseDataSet = ticketObj.DownloadTicketsHistory(MyConfig.MyConnectionString, ticket);

            int temp  = responseDataSet.Tables.Count;
            int temp2 = responseDataSet.Tables[0].Rows.Count;
            int temp3 = responseDataSet.Tables[1].Rows.Count;

            if (responseDataSet != null)
            {
                if (responseDataSet.Tables.Count > 0)
                {
                    string file_name = "";
                    try
                    {
                        var book  = new XSSFWorkbook();
                        var sheet = book.CreateSheet("Sheet1");
                        Logger.Info("DownloadExcelReports started 1");
                        dynamic headerRow = sheet.CreateRow(0);
                        headerRow.CreateCell(0).SetCellValue("Agent Name");
                        headerRow.CreateCell(1).SetCellValue("Ticket Number");
                        headerRow.CreateCell(2).SetCellValue("Status");
                        headerRow.CreateCell(3).SetCellValue("Type Of Service");
                        headerRow.CreateCell(4).SetCellValue("Priority");
                        headerRow.CreateCell(5).SetCellValue("Ticket Created Time");
                        headerRow.CreateCell(6).SetCellValue("Ticket Updated Time");
                        headerRow.CreateCell(7).SetCellValue("Ticket Updated by");
                        headerRow.CreateCell(8).SetCellValue("Due Date");
                        if (responseDataSet.Tables[0].Rows.Count > 0)
                        {
                            var _with1 = responseDataSet.Tables[0];
                            for (int i = 0; i <= _with1.Rows.Count - 1; i++)
                            {
                                dynamic row = sheet.CreateRow(i + 1);
                                for (int c = 0; c <= responseDataSet.Tables[0].Columns.Count - 1; c++)
                                {
                                    row.CreateCell(c).SetCellValue(_with1.Rows[i][c].ToString());
                                }
                            }
                        }

                        string folderPath = "";
                        folderPath = HttpContext.Current.Server.MapPath("~/TicketHistory/");
                        // floderName = "ScriptFileUpload";
                        if (!Directory.Exists(folderPath))
                        {
                            Directory.CreateDirectory(folderPath);
                        }

                        string path = System.Web.HttpContext.Current.Server.MapPath("~");
                        file_name = "TicketHistory_" + DateTime.Now.ToString("ddMMyyyyHHmmssfff") + ".xlsx";
                        FileStream exportData = new FileStream(path + "/TicketHistory/" + file_name, FileMode.CreateNew);
                        book.Write(exportData);
                        HttpContext.Current.Response.Clear();
                        HttpContext.Current.Response.ClearHeaders();
                        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
                        HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", file_name));
                        System.IO.FileInfo Dfile = new System.IO.FileInfo(path + "/TicketHistory/" + file_name);
                        HttpContext.Current.Response.WriteFile(Dfile.FullName);
                        exportData.Close();
                        HttpContext.Current.Response.Flush();
                        System.IO.File.Delete(path + "/TicketHistory/" + file_name);
                        HttpContext.Current.Response.End();
                    }
                    catch (Exception ex)
                    {
                        Logger.Info("DownloadExcelReports " + ex.ToString());
                    }
                }
            }
        }