public void LoadReport()
        {
            try
            {
                if (dtpFromDate.Value != null && dtpFromDate.Value.Value.Year == 1753)
                {
                    dtpFromDate.Value = null;
                }

                if (dtpTillDate.Value != null && dtpTillDate.Value.Value.Year == 1753)
                {
                    dtpTillDate.Value = null;
                }

                DateTime?fromDates = dtpFromDate.Value.ToDateorNull();
                DateTime?tillDates = dtpTillDate.Value.ToDateorNull();

                int HourRange = numHourRange.Value.ToInt();
                if (HourRange == 0 || HourRange > 24)
                {
                    HourRange          = 2;
                    numHourRange.Value = HourRange;
                }


                string Error = "";
                if (fromDates == null)
                {
                    Error = "Required : From Date";
                }
                if (tillDates == null)
                {
                    if (string.IsNullOrEmpty(Error))
                    {
                        Error = "Required : Till Date";
                    }
                    else
                    {
                        Error += Environment.NewLine + "Required : Till Date";
                    }
                }
                if (!string.IsNullOrEmpty(Error))
                {
                    ENUtils.ShowMessage(Error);
                    return;
                }

                if (fromDates != null && dtpFromTime.Value != null && dtpFromTime.Value.Value != null)
                {
                    fromDates = (fromDates.Value.ToDate() + dtpFromTime.Value.Value.TimeOfDay).ToDateTime();
                }



                if (tillDates != null && dtptilltime.Value != null && dtptilltime.Value.Value != null)
                {
                    tillDates = (tillDates.Value.ToDate() + dtptilltime.Value.Value.TimeOfDay).ToDateTime();
                }



                this.reportViewer1.LocalReport.EnableExternalImages = true;

                var list = (from a in GeneralBLL.GetQueryable <CallHistory>(null)
                            where (a.CallDateTime >= fromDates) &&
                            (a.CallDateTime <= tillDates)
                            orderby a.CallDateTime descending
                            //where (a.AnsweredDateTime.Value.Date >= fromDates)
                            //&& (a.AnsweredDateTime.Value.Date <= tillDates)
                            //orderby a.AnsweredDateTime descending
                            select new
                {
                    CallDateTime = a.CallDateTime,
                }).ToList();



                List <NewCallHistory> objCallHistory = new List <NewCallHistory>();

                List <NewCallHistory> objNewCallHistory = new List <NewCallHistory>();

                DateTime dtFrom = DateTime.Now.ToDate();
                DateTime dtTo   = DateTime.Now.ToDate();

                int    GroupHours    = 24;
                string HoursDuration = "";

                var grouplist = list.GroupBy(c => c.CallDateTime.ToDate()).ToList();;

                foreach (var item in grouplist)
                {
                    int i = 0;
                    dtFrom = item.Key.ToDate();
                    dtTo   = item.Key.ToDate();

                    for (; i < GroupHours; i += HourRange)
                    {
                        if (i == 0)
                        {
                            dtTo = item.Key.AddHours(HourRange);
                        }
                        else
                        {
                            dtFrom = item.Key.AddHours(i);

                            dtTo = item.Key.AddHours((i + HourRange));
                            if (dtFrom.Date != dtTo.Date)
                            {
                                dtTo = new DateTime(dtFrom.Year, dtFrom.Month, dtFrom.Day, 23, 59, 59);
                            }
                        }
                        objCallHistory.Add(new NewCallHistory {
                            FromTime = dtFrom, ToTime = dtTo
                        });
                    }
                }

                foreach (var item in objCallHistory)
                {
                    dtFrom = item.FromTime.ToDateTime();
                    dtTo   = item.ToTime.ToDateTime();
                    var obj = list.Where(c => c.CallDateTime >= item.FromTime && c.CallDateTime <= item.ToTime).ToList();;
                    if (obj.Count > 1)
                    {
                        objNewCallHistory.RemoveAll(c => c.FromTime >= dtFrom && c.FromTime <= dtTo);
                    }
                    if (obj.Count > 0)
                    {
                        HoursDuration = string.Format("{0:HH:mm}", dtFrom) + " to " + string.Format("{0:HH:mm}", dtTo);
                        objNewCallHistory.Add(new NewCallHistory {
                            FromTime = dtFrom, ToTime = dtTo, Id = obj.Count, CalledToNumber = HoursDuration, CallDateTime = dtFrom.ToDate()
                        });
                    }
                }


                if (chkIncludeZeroCalls.Checked)
                {
                    foreach (var item in grouplist)
                    {
                        int i = 0;
                        dtFrom = item.Key.ToDateTime();
                        dtTo   = item.Key.ToDateTime();

                        for (; i < GroupHours; i += HourRange)
                        {
                            if (i == 0)
                            {
                                dtTo = item.Key.AddHours(HourRange);
                            }
                            else
                            {
                                dtFrom = item.Key.AddHours(i);
                                dtTo   = item.Key.AddHours((i + HourRange));
                                if (dtFrom.Date != dtTo.Date)
                                {
                                    dtTo = new DateTime(dtFrom.Year, dtFrom.Month, dtFrom.Day, 23, 59, 59);
                                }
                            }
                            if (objNewCallHistory.Count(c => c.FromTime == dtFrom && c.ToTime == dtTo) == 0)
                            {
                                HoursDuration = string.Format("{0:HH:mm}", dtFrom) + " to " + string.Format("{0:HH:mm}", dtTo);
                                objNewCallHistory.Add(new NewCallHistory {
                                    FromTime = dtFrom, ToTime = dtTo, Id = 0, CalledToNumber = HoursDuration, CallDateTime = dtFrom.ToDate()
                                });
                            }
                        }
                    }
                }



                objNewCallHistory = objNewCallHistory.OrderBy(c => c.FromTime).ToList();
                this.CallHistoryBindingSource.DataSource = objNewCallHistory;



                Microsoft.Reporting.WinForms.ReportParameter[] param = new Microsoft.Reporting.WinForms.ReportParameter[4];

                string heading = string.Empty;
                if (fromDates != null && tillDates != null)
                {
                    heading = string.Format("{0:dd/MM/yy HH:mm}", fromDates) + " to " + string.Format("{0:dd/MM/yy HH:mm}", tillDates);
                }


                param[0] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Period", heading);
                param[1] = new Microsoft.Reporting.WinForms.ReportParameter("ReportParameterHeader", AppVars.objSubCompany.CompanyName);
                param[2] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Address", AppVars.objSubCompany.Address);
                param[3] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Telephone", AppVars.objSubCompany.TelephoneNo);

                //Report_Parameter_Telephone
                //param[2] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_TotalJobs", jobsDone);


                //List<ClsLogo> objLogo = new List<ClsLogo>();
                //objLogo.Add(new ClsLogo { ImageInBytes = AppVars.objSubCompany.CompanyLogo != null ? AppVars.objSubCompany.CompanyLogo.ToArray() : null });
                //ReportDataSource imageDataSource = new ReportDataSource("Taxi_AppMain_Classes_ClsLogo", objLogo);
                //this.reportViewer1.LocalReport.DataSources.Add(imageDataSource);

                reportViewer1.LocalReport.SetParameters(param);



                this.reportViewer1.ZoomPercent = 100;
                this.reportViewer1.ZoomMode    = Microsoft.Reporting.WinForms.ZoomMode.Percent;
                this.reportViewer1.RefreshReport();
                IsReportLoaded = true;
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }
        private void GenerateReport()
        {
            try
            {
                bool isMissed = optMissedCalls.Checked;



                if (dtpFromDate.Value != null && dtpFromDate.Value.Value.Year == 1753)
                {
                    dtpFromDate.Value = null;
                }

                if (dtpTillDate.Value != null && dtpTillDate.Value.Value.Year == 1753)
                {
                    dtpTillDate.Value = null;
                }

                DateTime?fromDate = dtpFromDate.Value.ToDateorNull();
                DateTime?tillDate = dtpTillDate.Value.ToDateorNull();

                string phone = txtPhone.Text.Trim();
                string name  = txtName.Text.Trim().ToLower();
                string Line  = txtLine.Text.ToStr();
                string Stn   = txtStn.Text.ToStr();


                var list = (from a in GeneralBLL.GetQueryable <CallHistory>(null)
                            where (fromDate == null || a.CallDateTime.Value.Date >= fromDate) &&
                            (tillDate == null || a.CallDateTime.Value.Date <= tillDate) &&
                            (name == string.Empty || a.Name.Trim().ToLower().StartsWith(name)) &&
                            (phone == string.Empty || a.PhoneNumber.Trim() == phone) &&
                            (Line == string.Empty || a.Line == Line) &&
                            (Stn == string.Empty || a.STN == Stn) &&
                            (isMissed == false || (a.IsAccepted != null && a.IsAccepted == true))
                            orderby a.CallDateTime descending
                            select new
                {
                    Name = a.Name,
                    PhoneNumber = a.PhoneNumber,
                    CallDateTime = a.CallDateTime,
                    Line = a.Line,
                    STN = a.STN
                }).ToList();



                CallHistoryBindingSource.DataSource = list;



                Microsoft.Reporting.WinForms.ReportParameter[] param = new Microsoft.Reporting.WinForms.ReportParameter[6];

                string address = AppVars.objSubCompany.Address;
                string telNo   = "Tel No. " + AppVars.objSubCompany.TelephoneNo;

                param[0] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Header", AppVars.objSubCompany.CompanyName.ToStr());
                param[1] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Address", address);
                param[2] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Telephone", telNo);

                string heading = string.Empty;
                if (fromDate != null && tillDate != null)
                {
                    heading = string.Format("{0:dd/MM/yyyy}", fromDate) + " to " + string.Format("{0:dd/MM/yyyy}", tillDate);
                }
                param[3] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_Criteria", heading);
                param[4] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_TotalCalls", list.Count.ToStr());


                CallerIdType_Configuration obj = General.GetObject <CallerIdType_Configuration>(c => c.Id != null);
                string DigitalCLIType          = obj.DigitalCLIType.ToStr();

                param[5] = new Microsoft.Reporting.WinForms.ReportParameter("Report_Parameter_DigitalCLIType", DigitalCLIType == "" ? "0" : DigitalCLIType);

                reportViewer1.LocalReport.SetParameters(param);

                this.reportViewer1.ZoomPercent = 100;
                this.reportViewer1.ZoomMode    = Microsoft.Reporting.WinForms.ZoomMode.Percent;
                this.reportViewer1.RefreshReport();
            }
            catch (Exception ex)
            {
                ENUtils.ShowMessage(ex.Message);
            }
        }
예제 #3
0
        public override void PopulateData()
        {
            if (dtpFromDate.Value != null && dtpFromDate.Value.Value.Year == 1753)
            {
                dtpFromDate.Value = null;
            }

            if (dtpTillDate.Value != null && dtpTillDate.Value.Value.Year == 1753)
            {
                dtpTillDate.Value = null;
            }

            DateTime?fromDate = dtpFromDate.Value.ToDateorNull();
            DateTime now      = DateTime.Now.ToDateTime();
            DateTime?tillDate = dtpTillDate.Value.ToDateorNull();



            string hours = ddlHours.SelectedItem.ToStr();
            var    total = DateTime.Now.AddHours(-hours.ToInt());


            //var list = (from a in GeneralBLL.GetQueryable<Vw_CallStat>(null).AsEnumerable()
            //            where (fromDate == null || a.CallDateTime.ToDate() >= fromDate)
            //             && (tillDate == null || a.CallDateTime.ToDate() <= tillDate)
            //            orderby a.CallDateTime descending
            //            select new
            //        {
            //            Name = a.Name,
            //            PhoneNumber = a.PhoneNumber,
            //            CallDateTime = a.CallDateTime,
            //            No = a.NoOfCalls
            //        }).ToList();



            var list = (from a in GeneralBLL.GetQueryable <Vw_CallStat>(c => c.CallDateTime >= total && c.CallDateTime <= now).AsEnumerable()
                        orderby a.CallDateTime descending


                        select new
            {
                Name = a.Name,
                PhoneNumber = a.PhoneNumber,
                CallDateTime = a.CallDateTime,
                No = a.NoOfCalls
            }).ToList();


            grdStats.DataSource = list;
            //   DriverChart.Series[0].Points.Clear();


            foreach (var obj in list)
            {
                //DataPoint point = new DataPoint();
                //point.Label = obj.Name;
                //point.AxisLabel = obj.PhoneNumber;
                //point.LabelForeColor = Color.Navy;
                //point.LabelToolTip = obj.Name;
                //point.YValues[0] = (double)obj.No;
                //point.SetCustomProperty("BarLabelStyle", "Outside");
                //if (obj.PhoneNumber.Contains("abcdefghijklmnopqrstuvwxyz"))
                //{
                //}
                //else
                //{
                //    point.XValue = Convert.ToDouble(obj.PhoneNumber);
                //}
                //  DriverChart.Series[0].Points.Add(point);
            }

            //grdStats.Columns["ID"].IsVisible = false;
            //grdStats.Columns["Accepted"].IsVisible = false;
            grdStats.Columns["Name"].Width         = 170;
            grdStats.Columns["PhoneNumber"].Width  = 150;
            grdStats.Columns["CallDateTime"].Width = 180;
            //(grdStats.Columns["CallDateTime"] as GridViewDateTimeColumn).CustomFormat = "dd/MM/yyyy";
            grdStats.Columns["CallDateTime"].HeaderText = "Call Date Time";
        }