private void ShowReport(string reportMode)
        {
            CriteriaOperator criteria = ((fmCRHUnpayedRequest)View.CurrentObject).GetCriteria();

            // Определяем тип объектов отчёта
            Type dsType = typeof(fmCRHUnpayedRequestContractLine);

            // Получаем название файла (без расширения, которое всегда .repx) разметки отчёта
            string reportFileName = "fmCRHUnpayedRequestLine";


            // Создаём для отчёта отдельный ObjectSpace
            IObjectSpace objectSpace = Application.CreateObjectSpace();

            // Создаём объект, чтобы вызвать в нём метод фомирования коллекции
            fmCRHUnpayedRequest obj = View.CurrentObject as fmCRHUnpayedRequest;

            if (obj == null)
            {
                return;
            }

            // Находим сессию
            Session ssn = ((ObjectSpace)objectSpace).Session;

            string   fname = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            FileInfo fi    = new FileInfo(fname);

            string checkDir = fi.Directory.FullName + "\\Reports\\";


            // http://www.devexpress.com/Support/Center/p/Q135993.aspx
            //XafExtReport rep = new XafExtReport();
            XafReport rep = new XafReport();

            rep.LoadLayout(checkDir + reportFileName + ".repx");

            if (reportMode == "Short")
            {
                for (int i = 0; i < rep.Bands.Count; i++)
                {
                    if (rep.Bands[i].Name == "detailBand1")
                    {
                        rep.Bands[i].Visible = false;
                    }
                }
            }

            rep.DataSource = obj.CreateReportListSource(ssn, criteria);

            //rep.ShowDesignerDialog();
            rep.ShowPreview();
        }
Ejemplo n.º 2
0
        private void ShowReport(string reportMode)
        {
            fmCRHPayedRequestReportParameters current = View.CurrentObject as fmCRHPayedRequestReportParameters;

            if (current == null)
            {
                return;
            }

            // Создаём для отчёта отдельный ObjectSpace
            IObjectSpace objectSpace = ObjectSpace;   //ObjectSpace;   // Application.CreateObjectSpace();

            /*
             * // Определяем тип объектов отчёта
             * Type dsType = typeof(fmCRHPayedRequestNonPersistent);
             *
             * // Получаем название файла (без расширения, которое всегда .repx) разметки отчёта
             * string reportFileName = "fmCRHPayedRequestReport";
             *
             * string fname = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
             * FileInfo fi = new FileInfo(fname);
             *
             * string checkDir = fi.Directory.FullName + "\\Reports\\";
             *
             * // http://www.devexpress.com/Support/Center/p/Q135993.aspx
             * //XafExtReport rep = new XafExtReport();
             * XafReport rep = new XafReport();
             * rep.LoadLayout(checkDir + reportFileName + ".repx");
             */

            /*
             * if (reportMode == "Short") {
             *  for (int i = 0; i < rep.Bands.Count; i++) {
             *      if (rep.Bands[i].Name == "detailBand1") {
             *          rep.Bands[i].Visible = false;
             *      }
             *  }
             * }
             */

            //IReportData reportData = ObjectSpace.FindObject<ReportData>(new BinaryOperator("Name", "fmCRHPayedRequestReport"));
            IReportData reportData = ObjectSpace.FindObject <ReportData>(new BinaryOperator("Name", "Список оплаченных счетов"));
            XafReport   rep        = reportData.LoadXtraReport(objectSpace);

            rep.DataSource = current.GenerateReportContent();

            //rep.ShowDesignerDialog();
            rep.ShowPreview();
        }
Ejemplo n.º 3
0
        //private void BookRegister_Execute(object sender, SimpleActionExecuteEventArgs e)
        //{
        //    double numcredits = 0;
        //    Decimal sumTuitionFee = 0;
        //    ListEditor listEditor = ((ListView)View).Editor as ListEditor;
        //    PopUpMessage ms;
        //    DialogController dc;
        //    ObjectSpace objectSpace = Application.CreateObjectSpace();
        //    if (listEditor != null)
        //    {
        //        if (SecuritySystem.CurrentUser is Student)
        //        {

        //            //kiem tra rang buoc so tin chi min
        //            foreach (RegisterDetail regDetail in ((ListView)View).SelectedObjects)
        //            {
        //                numcredits += regDetail.Lesson.Subject.Credit;

        //            }
        //            ConstrainstParameter cparam = objectSpace.FindObject<ConstrainstParameter>(
        //            new BinaryOperator("Code", "MINCREDITS"));
        //            if (cparam != null && numcredits < Convert.ToDouble(cparam.Value))
        //            {

        //                ms = objectSpace.CreateObject<PopUpMessage>();
        //                ms.Title = "Lỗi đăng ký";
        //                ms.Message = string.Format("Không đăng ký ít hơn {0} tín chỉ!", cparam.Value);
        //                e.ShowViewParameters.CreatedView = Application.CreateDetailView(
        //                     objectSpace, ms);
        //                e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
        //                e.ShowViewParameters.CreatedView.Caption = "Thông báo";
        //                dc = Application.CreateController<DialogController>();
        //                dc.AcceptAction.Active.SetItemValue("object", false);
        //                dc.CancelAction.Caption = "Đóng";
        //                dc.SaveOnAccept = false;
        //                e.ShowViewParameters.Controllers.Add(dc);

        //                return;
        //            }
        //            //kiem tra rang buoc so tin chi max
        //            cparam = View.ObjectSpace.FindObject<ConstrainstParameter>(
        //            new BinaryOperator("Code", "MAXCREDITS"));
        //            if (cparam != null && numcredits > Convert.ToDouble(cparam.Value))
        //            {

        //                ms = objectSpace.CreateObject<PopUpMessage>();
        //                ms.Title = "Lỗi đăng ký";
        //                ms.Message = string.Format("Không đăng ký nhiều hơn {0} tín chỉ!", cparam.Value);
        //                e.ShowViewParameters.CreatedView = Application.CreateDetailView(
        //                     objectSpace, ms);
        //                e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
        //                e.ShowViewParameters.CreatedView.Caption = "Thông báo";
        //                dc = Application.CreateController<DialogController>();
        //                dc.AcceptAction.Active.SetItemValue("object", false);
        //                dc.CancelAction.Caption = "Đóng";
        //                dc.SaveOnAccept = false;
        //                e.ShowViewParameters.Controllers.Add(dc);


        //                return;
        //            }

        //            numcredits = 0;
        //            sumTuitionFee = 0;
        //            string lessonCodelist = "";

        //            foreach (RegisterDetail regDetail in ((ListView)View).SelectedObjects)
        //            {
        //                if (regDetail.RegisterState.Code == "SELECTED")
        //                {
        //                    numcredits += regDetail.Lesson.Subject.Credit;
        //                    sumTuitionFee += regDetail.Lesson.TuitionFee;
        //                    View.ObjectSpace.SetModified(regDetail);
        //                    View.ObjectSpace.SetModified(regDetail.Lesson);
        //                    regDetail.RegisterState = View.ObjectSpace.FindObject<RegisterState>(
        //                        new BinaryOperator ("Code","BOOKED"));
        //                    regDetail.CheckState = View.ObjectSpace.FindObject<RegisterState>(
        //                        new BinaryOperator("Code", "NOTCHECKED"));
        //                    regDetail.Lesson.NumRegistration++;
        //                    lessonCodelist += (String.Format("{0}({1})-", regDetail.Lesson.LessonName, regDetail.Lesson.Subject.SubjectCode));
        //                }
        //            }
        //            lessonCodelist = lessonCodelist.TrimEnd('-');
        //            //create Account transaction
        //            AccountTransaction act = View.ObjectSpace.CreateObject<AccountTransaction>();
        //            Student stud = View.ObjectSpace.FindObject<Student>(
        //                new BinaryOperator("Oid", SecuritySystem.CurrentUserId));
        //            act.Student = stud;
        //            act.MoneyAmount = -sumTuitionFee;
        //            act.TransactingDate = DateTime.Now;
        //            act.Description = string.Format("Học phí [{0}] phải đóng cho {1} tín chỉ đăng ký: [{2}], do [{3}] thực hiện đăng ký", stud.StudentCode, numcredits, lessonCodelist, stud.FullName);
        //            act.Save();

        //            View.ObjectSpace.CommitChanges();

        //            ms = objectSpace.CreateObject<PopUpMessage>();
        //            ms.Title = "Thực hiện đăng ký thành công";
        //            ms.Message = string.Format("Bạn đã chọn đăng ký {0} nhóm lớp môn học, với số tiền {1}", numcredits, sumTuitionFee);
        //            ms.Message += "\r\n Vui lòng xem kết quả giao dịch học phí!!!";
        //            e.ShowViewParameters.CreatedView = Application.CreateDetailView(
        //                 objectSpace, ms);
        //            e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
        //            e.ShowViewParameters.CreatedView.Caption = "Thông báo";
        //            dc = Application.CreateController<DialogController>();
        //            dc.AcceptAction.Active.SetItemValue("object", false);
        //            dc.CancelAction.Caption = "Đóng";
        //            dc.SaveOnAccept = false;
        //            e.ShowViewParameters.Controllers.Add(dc);

        //        }
        //        else
        //        {

        //            Dictionary<string, double> studentnumcredits = new Dictionary<string, double>();
        //            Dictionary<string, decimal> studentFee = new Dictionary<string, decimal>();
        //            Dictionary<string, string> studentLessonCodeList = new Dictionary<string, string>();
        //            Dictionary<string, string> lessonCannotReg = new Dictionary<string, string>();
        //            foreach (RegisterDetail regDetail in View.SelectedObjects)
        //            {

        //                if (!studentnumcredits.ContainsKey(regDetail.Student.StudentCode))
        //                {
        //                    studentnumcredits.Add(regDetail.Student.StudentCode, 0);
        //                }
        //                if (!studentFee.ContainsKey(regDetail.Student.StudentCode))
        //                {
        //                    studentFee.Add(regDetail.Student.StudentCode, 0);
        //                }
        //                if (!studentLessonCodeList.ContainsKey(regDetail.Student.StudentCode))
        //                {
        //                    studentLessonCodeList.Add(regDetail.Student.StudentCode, "");
        //                }
        //                View.ObjectSpace.SetModified(regDetail);
        //                View.ObjectSpace.SetModified(regDetail.Lesson);
        //                if (regDetail.RegisterState.Code == "SELECTED")
        //                {
        //                    if (regDetail.Lesson.NumRegistration >= regDetail.Lesson.NumExpectation)
        //                    {
        //                        if (!lessonCannotReg.ContainsKey(regDetail.Lesson.LessonName))
        //                        {
        //                            lessonCannotReg.Add(regDetail.Lesson.LessonName, "");
        //                        }
        //                        lessonCannotReg[regDetail.Lesson.LessonName] += string.Format("[{0}]-", regDetail.Student.StudentCode);
        //                        regDetail.Note = "Over Sized";
        //                    }
        //                    else
        //                    {
        //                        studentnumcredits[regDetail.Student.StudentCode] += regDetail.Lesson.Subject.Credit;
        //                        studentFee[regDetail.Student.StudentCode] += regDetail.Lesson.TuitionFee;
        //                        studentLessonCodeList[regDetail.Student.StudentCode] += (String.Format("{0}({1})-", regDetail.Lesson.LessonName, regDetail.Lesson.Subject.SubjectCode));


        //                        regDetail.RegisterState = View.ObjectSpace.FindObject<RegisterState>(
        //                        new BinaryOperator("Code", "BOOKED"));
        //                        regDetail.Lesson.NumRegistration++;
        //                    }
        //                }
        //            }
        //            int numstudent = 0;
        //            double credit = 0;
        //            decimal sumfee = 0;
        //            foreach (string studCode in studentLessonCodeList.Keys)
        //            {
        //                if (studentnumcredits[studCode] > 0)
        //                {
        //                    numstudent++;
        //                    credit += studentnumcredits[studCode];
        //                    sumfee += studentFee[studCode];

        //                    //create Account transaction
        //                    AccountTransaction act = View.ObjectSpace.CreateObject<AccountTransaction>();
        //                    Student studnew = View.ObjectSpace.FindObject<Student>(
        //                        new BinaryOperator("StudentCode", studCode));
        //                    act.Student = studnew;
        //                    act.MoneyAmount = -studentFee[studCode];
        //                    act.TransactingDate = DateTime.Now;
        //                    act.Description = string.Format("Học phí sinh viên [{0}] phải đóng cho {1} tín chỉ đăng ký là {2:0,0},\r\n bao gồm: [{3}],\r\n [{4}] thực hiện đăng ký",
        //                        studnew.StudentCode, studentnumcredits[studCode], studentFee[studCode], studentLessonCodeList[studCode].TrimEnd('-'), SecuritySystem.CurrentUserName);
        //                    act.Save();
        //                }
        //            }

        //            View.ObjectSpace.CommitChanges();

        //            ms = objectSpace.CreateObject<PopUpMessage>();
        //            ms.Title = "Thực hiện đăng ký (Booked) thành công";
        //            ms.Message = string.Format("Bạn đã chọn đăng ký cho {0} sinh viên, với số tiền {1:0,0} cho tổng số {2:0,0} tín chỉ học",
        //                numstudent, sumfee, credit);
        //            ms.Message += "\r\n Vui lòng xem kết quả giao dịch học phí!!!";
        //            if (lessonCannotReg.Count > 0)
        //            {
        //                string strmessage = "";
        //                foreach (KeyValuePair<string, string> keypair in lessonCannotReg)
        //                {
        //                    strmessage += string.Format("Nhóm lớp MH:[{0}], sinh viên [{1}] \r\n", keypair.Key, keypair.Value.TrimEnd('-'));
        //                }
        //                ms.Message += "\r\nKhông đăng ký được do quá sĩ số:\r\n" + strmessage;
        //            }
        //            e.ShowViewParameters.CreatedView = Application.CreateDetailView(
        //                 objectSpace, ms);
        //            e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
        //            e.ShowViewParameters.CreatedView.Caption = "Thông báo";
        //            dc = Application.CreateController<DialogController>();
        //            e.ShowViewParameters.Controllers.Add(dc);
        //            dc.AcceptAction.Active.SetItemValue("object", false);
        //            dc.CancelAction.Caption = "Đóng";
        //            dc.SaveOnAccept = false;
        //        }
        //    }
        //}
        //private void ConfirmRegister_Execute(object sender, SimpleActionExecuteEventArgs e)
        //{

        //    ListEditor listEditor = ((ListView)View).Editor as ListEditor;
        //    if (listEditor != null)
        //    {
        //        int i = 0;
        //        string messsage = "";
        //        ObjectSpace objectSpace = Application.CreateObjectSpace();
        //        PopUpMessage ms = objectSpace.CreateObject<PopUpMessage>();
        //        ms.Message = messsage;
        //        DialogController dc = Application.CreateController<DialogController>();
        //        if (View.SelectedObjects.Count > 0)
        //        {
        //            foreach (RegisterDetail regDetail in ((ListView)View).SelectedObjects)
        //            {
        //                regDetail.RegisterState = View.ObjectSpace.FindObject<RegisterState>(
        //                        new BinaryOperator("Code", "PRINTED"));
        //                if (regDetail.CheckState.Code == "CHECKED")
        //                {
        //                    View.ObjectSpace.SetModified(regDetail);
        //                    regDetail.CheckState = View.ObjectSpace.FindObject<RegisterState>(
        //                        new BinaryOperator("Code", "CONFIRMED"));
        //                    i++;
        //                }
        //            }
        //            View.ObjectSpace.CommitChanges();
        //            messsage = string.Format("Đã xác nhận kết quả cho \"{0}\" Nhóm MH, \r\n Nhấn OK để in kết quả!", i);
        //            ms.Title = "Kết quả xác nhận!";
        //            dc.Accepting += dc_Accepting_Report;
        //            dc.SaveOnAccept = false;
        //        }
        //        else
        //        {
        //            messsage = "Vui lòng chọn tất cả các môn đã kiểm tra";
        //            ms.Title = "Chưa chọn môn xác nhận!";
        //        }


        //        e.ShowViewParameters.CreatedView = Application.CreateDetailView(
        //            objectSpace, ms);
        //        e.ShowViewParameters.TargetWindow = TargetWindow.NewModalWindow;
        //        e.ShowViewParameters.CreatedView.Caption = "Thông báo";
        //        e.ShowViewParameters.Controllers.Add(dc);
        //    }
        //}

        #endregion

        void dc_Accepting_Report(object sender, DialogControllerAcceptingEventArgs e)
        {
            Controller  controller  = sender as Controller;
            ObjectSpace objectSpace = Application.CreateObjectSpace();
            ReportData  rd          = objectSpace.FindObject <ReportData>(
                new BinaryOperator("Name", "Kết quả ĐK 1 SV"));

            if (rd != null)
            {
                XafReport report = rd.LoadXtraReport(objectSpace);

                CriteriaOperator criteriaOperator = CriteriaOperator.TryParse(
                    String.Format("[Student.Oid] = '{0}'", SecuritySystem.CurrentUserId));
                Student student = objectSpace.FindObject <Student>(criteriaOperator);
                report.Filtering.Filter = criteriaOperator.ToString();
                MemoryStream stream = new MemoryStream();
                report.ExportToPdf(stream);
                if (HttpContext.Current != null)
                {
                    byte[] buffer             = stream.GetBuffer();
                    string contentType        = "application/pdf";
                    string contentDisposition = "attachment; filename=" + student.StudentCode + ".pdf";
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Buffer = false;
                    HttpContext.Current.Response.AppendHeader("Content-Type", contentType);
                    HttpContext.Current.Response.AppendHeader("Content-Transfer-Encoding", "binary");
                    HttpContext.Current.Response.AppendHeader("Content-Disposition", contentDisposition);
                    HttpContext.Current.Response.BinaryWrite(buffer);
                    HttpContext.Current.Response.End();
                }
                else
                {
                    report.ShowPreview();
                }
                controller.Dispose();
            }
        }