Esempio n. 1
0
        public UIFS.SQL SQL; // SQL (a database) is essential and used everywhere in this module

        #endregion Fields

        #region Constructors

        public Reporting(ref SQL SQL)
        {
            this.SQL = SQL;

            // Load information needed to operate (settings)
            try
            {
                SQL.Query = SQL.SQLQuery.Reporting_Settings_FormLink;
                SQL.cmd = SQL.Command(SQL.Data);
                SQL.sdr = SQL.cmd.ExecuteReader(); SQL.sdr.Read();
                // "FormLinks" is how the application lets UIFS know what Subjects/Details are "tied" to a UIFS.Form
                this.FormLinks = (FormLink)JsonConvert.DeserializeObject(SQL.sdr.GetString(0), typeof(FormLink));
                SQL.sdr.Close();
            }
            catch (Exception ex)
            { // ERROR: failed to load needed data for reporting engine
                SQL.WriteLog_Error(ex, "Failed to load needed data for reporting engine", "UIFS.Reporting()");
            }
        }
Esempio n. 2
0
            /* /---[ Subject_Set       ]--------------------------------------------------------------------\
             * | Loads all the ReportConditions based on Subject (does not matter if a new report or existing one)
             * |
             * \-------------------------------------------------------------------/
             * isnew    =   false if loading/editing an existing RD  (otherwise if a new Subject is chosen, TRUE to rebuild)
             *
             */
            public bool Subject_Set(bool isnew, ref FormLink Formlinks, ReportingSubject RS, ref SQL SQL, ref ReportingSubject[] ReportingSubjects)
            {
                bool exists = false;
                ReportingSubject.Detail RSdetail;
                ReportDefinition.Detail existingRDdetail = new ReportDefinition.Detail();
                FormControl UIFSFormControl;
                if (isnew || this.ReportConditions == null)
                {
                    this.ReportConditions = new ReportCondition[0]; // starting over fresh...should this be possible?
                }

                //. setup [globals]
                foreach (FormLink.Detail FLdetail in Formlinks.Details) {
                    int iRDDd=-1; // holds the index of the RD.Desc.detail for linking the ReportCondition to the actual RD.Description...
                    switch (FLdetail.type)
                    {
                        // -[ Global Subject ]-
                        // this behaves as a "pointer"/collection of id(s) to reference a Subject or set of Subjects to filter by...
                        // this is a UIFS standard, but for UX simplification (This "subject" has a corresponding id field that is unique to each form created)
                        case "Subject":
                            if (!isnew) { // check to see if exists in current RD
                                for (int t=0;t<RD.Description.Details.Length;t++) {
                                    if ("[global]"+FLdetail.name == RD.Description.Details[t].name)
                                    {
                                        existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                        exists = true; break;
                                    }
                                }
                            }
                            RSdetail = new ReportingSubject.Detail();
                            RSdetail.db = FLdetail.field;
                            RSdetail.name = "[global]" + FLdetail.name;
                            RSdetail.type = "id"; // this basically tells the application that this is a linked *Subject
                            Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                            ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                            if (exists)
                            {
                                ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                exists = false; // reset
                            }
                            //. Load subject selection data
                            int pscount=0; int iRS;
                            //. Find reporting subject
                            for (iRS = 0; iRS < ReportingSubjects.Length; iRS++)
                            {
                                if (ReportingSubjects[iRS].name == FLdetail.name) { break; }
                            }
                            SQL.Query = ReportingSubjects[iRS].BuildQuery_IDList(); // dynamic build...
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader();
                            while (SQL.sdr.Read())
                            {
                                Array.Resize(ref ReportConditions[ReportConditions.Length - 1].PossibleValues, pscount+1);
                                ReportConditions[ReportConditions.Length - 1].PossibleValues[pscount] = new FormControl.List.Item();
                                ReportConditions[ReportConditions.Length - 1].PossibleValues[pscount].value = SQL.sdr[0].ToString();
                                ReportConditions[ReportConditions.Length - 1].PossibleValues[pscount].name = SQL.sdr[1].ToString();
                                pscount += 1;
                            }
                            SQL.sdr.Close();
                            // Report Show possibility
                            ReportShow_Add(RSdetail.db, RSdetail.name, RSdetail.type);
                            break;
                        case "Detail":
                            if (!isnew)
                            { // check to see if exists in current RD
                                for (int t = 0; t < RD.Description.Details.Length; t++)
                                {
                                    if ("[global]" + FLdetail.name == RD.Description.Details[t].name)
                                    {
                                        existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                        exists = true; break;
                                    }
                                }
                            }
                            RSdetail = new ReportingSubject.Detail();
                            RSdetail.db = FLdetail.field;
                            RSdetail.name = "[global]" + FLdetail.name;
                            RSdetail.type = FLdetail.datatype;
                            Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                            ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                            if (exists)
                            {
                                ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                exists = false; // reset
                            }
                            // Report Show possibility
                            ReportShow_Add(RSdetail.db, RSdetail.name, RSdetail.type);
                            break;
                    }

                } // end globals

                // NOTE: Right now, reporting is based off of having a UIFS.Form selection as the MAIN SUBJECT
                //    This means we are not setup to handle any generic *Subject as the main...here and in BuildReport()

                // ONLY when a SINGLE *Form* is chosen can we use its details
                if (RD.Description.lang == "singular")
                {
                    exists = false;
                    //. Now we walk through our chosen "Subject"'s Details
                    // this is a UIFS.Form
                    if (RD.Description.name == "Form")
                    {
                        //. need to get data from UIFS.Form for advanced functionality
                        UIFS.Form UIFSForm = new Form(ref SQL);
                        UIFS.FormDataStruct UIFSFormData = new FormDataStruct();
                        DataType UIFSConvertDT = new DataType();
                        // TODO: diff form ver
                        if (!UIFSForm.Load(Convert.ToInt32(RD.Description.selection),-1, ref UIFSFormData))
                        {
                            SQL.WriteLog_Error(UIFSForm.ErrorEx, "Error loading form:" + RD.Description.selection, "UIFS.Reporting.GraphicalUserInterface.Subject_Set()");
                            return false;
                        }
                        //. walk through all form controls...
                        foreach (FormDataStruct.ControlListDetail CLD in UIFSFormData.ControlList)
                        {
                            int iRDDd = -1;
                            UIFSFormControl = UIFSFormData.Get_Control(CLD.id);
                            switch (CLD.type) {
                                case ControlType.Range: // Range Controls have 2 values
                                    FormControl.Range Ctrl_Range = (FormControl.Range)UIFSFormControl;
                                    //. create Start option
                                    RSdetail = new ReportingSubject.Detail();
                                    RSdetail.db = CLD.id.ToString()+"_Start";
                                    RSdetail.name = UIFSFormControl.name+" START";
                                    RSdetail.type = UIFSConvertDT.convertUIFS(Ctrl_Range.type.ToString());
                                    if (!isnew) { // check to see if exists in current RD
                                        for (int t = 0; t < RD.Description.Details.Length; t++) {
                                            if (RSdetail.db == RD.Description.Details[t].name){
                                                existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                                exists = true; break;
                                            }
                                        }
                                    }
                                    Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                                    ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                                    if (exists)
                                    {
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                        ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                        exists = false; // reset
                                    }
                                    //. create End option
                                    RSdetail = new ReportingSubject.Detail();
                                    RSdetail.db = CLD.id.ToString()+"_End";
                                    RSdetail.name = UIFSFormControl.name +" END";
                                    RSdetail.type = UIFSConvertDT.convertUIFS(Ctrl_Range.type.ToString());
                                    if (!isnew) { // check to see if exists in current RD
                                        for (int t = 0; t < RD.Description.Details.Length; t++) {
                                            if (RSdetail.db == RD.Description.Details[t].name){
                                                existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                                exists = true; break;
                                            }
                                        }
                                    }
                                    Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                                    ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                                    if (exists)
                                    {
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                        ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                        exists = false; // reset
                                    }
                                    // Report Show possibility
                                    switch (Ctrl_Range.type)
                                    {
                                        case FormControl.Range.Rangetype.DateRange:
                                        case FormControl.Range.Rangetype.TimeRange:
                                        case FormControl.Range.Rangetype.DateTimeRange:
                                            ReportShow_Add(CLD.id.ToString(), UIFSFormControl.name, "Range_DateTime");
                                            break;
                                        case FormControl.Range.Rangetype.MinMax:
                                        case FormControl.Range.Rangetype.Currency:
                                            ReportShow_Add(CLD.id.ToString(),UIFSFormControl.name,"Range_Number");//UIFSFormControl.name
                                            break;
                                    }
                                    break;
                                case ControlType.DateTime:
                                    FormControl.DateTime Ctrl_DateTime = (FormControl.DateTime)UIFSFormControl;
                                    RSdetail = new ReportingSubject.Detail();
                                    RSdetail.db = CLD.id.ToString();
                                    RSdetail.name = UIFSFormControl.name;
                                    RSdetail.type = UIFSConvertDT.convertUIFS(Ctrl_DateTime.type.ToString().ToLower()); // UIFS.ControlType..
                                    if (!isnew) { // check to see if exists in current RD
                                        for (int t = 0; t < RD.Description.Details.Length; t++) {
                                            if (RSdetail.db == RD.Description.Details[t].name){
                                                existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                                exists = true; break;
                                            }
                                        }
                                    }
                                    Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                                    ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                                    ReportConditions[ReportConditions.Length - 1].UIFSFormControl = true;
                                    ReportConditions[ReportConditions.Length - 1].UIFSControl = UIFSFormControl;
                                    ReportConditions[ReportConditions.Length - 1].UIFSFormControl_type = CLD.type;
                                    if (exists)
                                    {
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                        ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                        exists = false; // reset
                                    }
                                    // Report Show possibility
                                    ReportShow_Add(RSdetail.db, RSdetail.name, RSdetail.type);
                                    break;
                                default:
                                    RSdetail = new ReportingSubject.Detail();
                                    RSdetail.db = CLD.id.ToString();
                                    RSdetail.name = UIFSFormControl.name;
                                    RSdetail.type = UIFSConvertDT.convertUIFS(CLD.type.ToString().ToLower()); // UIFS.ControlType..
                                    if (!isnew) { // check to see if exists in current RD
                                        for (int t = 0; t < RD.Description.Details.Length; t++) {
                                            if (RSdetail.db == RD.Description.Details[t].name){
                                                existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                                exists = true; break;
                                            }
                                        }
                                    }
                                    Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                                    ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                                    ReportConditions[ReportConditions.Length - 1].UIFSFormControl = true;
                                    ReportConditions[ReportConditions.Length - 1].UIFSControl = UIFSFormControl;
                                    ReportConditions[ReportConditions.Length - 1].UIFSFormControl_type = CLD.type;
                                    if (exists)
                                    {
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                        ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                        exists = false; // reset
                                    }
                                    // Report Show possibility
                                    ReportShow_Add(RSdetail.db,RSdetail.name,RSdetail.type);

                                    break;
                            }
                        }
                    }

                    // NOT IMPLEMENTED
                    else
                    { // generic Subject, use the Reporting DB
                        foreach (ReportingSubject.Detail RSd in RS.Details)
                        {
                            Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                            ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSd, ReportConditions.Length - 1);
                            if (!isnew)
                            { // check to see if exists in current RD
                                foreach (ReportDefinition.Detail RDdetail in RD.Description.Details)
                                {
                                    if (RSd.name == RDdetail.name)
                                    { // if an RD is loaded, this gives us the selection details
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = RDdetail;
                                        break;
                                    }
                                }
                            }
                        }

                    }
                }

                // END of Subject_Set()
                return true;
            }