示例#1
0
        private int saveUserReportFields(int userReportID, List <RptField> fields, int userId, List <RptField> summarizeFields)
        {
            ReportProjectDBEntities entities = new ReportProjectDBEntities();

            UserReport ur = entities.UserReport.Where(urp => urp.UserReportID == userReportID).First();

            foreach (var field in fields)
            {
                string sortdir = "A";
                if (field.SortDirection == SortDirectionEnum.Descending)
                {
                    sortdir = "D";
                }

                UserReportField urf = new UserReportField();
                urf.UserReport       = ur;
                urf.ReportField      = entities.ReportField.Where(r => r.ReportFieldID == field.ReportFieldID).First();
                urf.CreatedByUserID  = userId;
                urf.CreatedDate      = DateTime.Now;
                urf.ColumnOrder      = field.ColumnOrder;
                urf.CustomName       = field.Name;
                urf.SortDirection    = sortdir;
                urf.SortOrder        = field.SortOrder;
                urf.GroupOrder       = field.GroupOrder;
                urf.IncludePageBreak = field.IncludePageBreak;
                urf.CoverageCode     = field.CoverageCode;
                entities.AddToUserReportField(urf);
            }

            entities.SaveChanges();

            saveUserReportSummarizeFields(summarizeFields, entities, ur, userId);

            return(ur.UserReportID);
        }
示例#2
0
        private int updateUserReportFields(int userReportID, List <RptField> fields, int userId, List <RptField> summarizeFields)
        {
            ReportProjectDBEntities entities = new ReportProjectDBEntities();

            UserReport ur = entities.UserReport.Where(urp => urp.UserReportID == userReportID).First();

            var userReportFielList = from fv in entities.UserReportField
                                     .Include("UserReport")
                                     where fv.UserReport.UserReportID == userReportID
                                     select fv;


            foreach (var field in userReportFielList)
            {
                if (!fields.Any(f => f.RptFieldID == field.UserReportFieldID))
                {
                    entities.UserReportField.DeleteObject(field);
                }
                else
                {
                    RptField myfield = fields.First(f => f.RptFieldID == field.UserReportFieldID);

                    string sortdir = "A";
                    if (myfield.SortDirection == SortDirectionEnum.Descending)
                    {
                        sortdir = "D";
                    }

                    UserReportField urf = new UserReportField();

                    field.ColumnOrder      = myfield.ColumnOrder;
                    field.SortOrder        = myfield.SortOrder;
                    field.SortDirection    = sortdir;
                    field.GroupOrder       = myfield.GroupOrder;
                    field.CustomName       = myfield.Name;
                    field.IncludePageBreak = myfield.IncludePageBreak;
                    field.CoverageCode     = myfield.CoverageCode;
                }
            }

            //Add New UserReportFields
            foreach (RptField field in fields)
            {
                if (field.RptFieldID == field.ReportFieldID)
                {
                    if (field.IsUsed || field.SortOrder > 0)
                    {
                        string sortdir = "A";
                        if (field.SortDirection == SortDirectionEnum.Descending)
                        {
                            sortdir = "D";
                        }

                        UserReportField urf = new UserReportField();

                        urf.UserReport       = ur;
                        urf.ReportField      = entities.ReportField.Where(r => r.ReportFieldID == field.RptFieldID).First();
                        urf.CreatedByUserID  = userId;
                        urf.CreatedDate      = DateTime.Now;
                        urf.ColumnOrder      = field.ColumnOrder;
                        urf.CustomName       = field.Name;
                        urf.SortDirection    = sortdir;
                        urf.SortOrder        = field.SortOrder;
                        urf.GroupOrder       = field.GroupOrder;
                        urf.IncludePageBreak = field.IncludePageBreak;
                        urf.CoverageCode     = field.CoverageCode;
                        entities.AddToUserReportField(urf);
                    }
                }
            }

            entities.SaveChanges();

            saveUserReportSummarizeFields(summarizeFields, entities, ur, userId);

            return(ur.UserReportID);
        }