/// <summary>
        /// Load an entry based from a given Phase
        /// </summary>
        /// <param name="targetPhase">PHASE1, PHASE2, PHASE3</param>
        /// <param name="perBatch"></param>
        /// <param name="currentBatch"></param>
        public DataTable LoadPhaseXFromDb(string targetPhase = "PHASE1", int perBatch = 50, int currentBatch = 1)
        {
            Dictionary <string, string> innerC = new Dictionary <string, string>()
            {
                ["Phase"] = targetPhase
            };

            MyDbUtils mdu = new MyDbUtils(this.DbPath);

            return(mdu.LoadEntriesViaSubquery(TABLE_NAME, perBatch, currentBatch, targetColumn: "FileName", innerCriteria: innerC));
        }
        /// <summary>
        /// Load an entry based from a given FileName and Username
        /// </summary>
        /// <param name="targetPhase">PHASE1, PHASE2, PHASE3</param>
        /// <param name="perBatch"></param>
        /// <param name="currentBatch"></param>
        public DataTable LoadFromDbViaFileNameAndUsername(string fileName, string emailUsername, int perBatch = 50, int currentBatch = 1)
        {
            Dictionary <string, string> criteriaX = new Dictionary <string, string>()
            {
                ["FileName"]      = fileName,
                ["EmailUsername"] = emailUsername
            };

            MyDbUtils mdu = new MyDbUtils(this.DbPath);

            return(mdu.LoadEntries(tableName: TABLE_NAME, orderBy: "Phase", perBatch: perBatch, currentBatch: currentBatch, criteria: criteriaX));
        }
        public DataTable LoadFromDbViaFileNameFromOutbound(string fileName, int perBatch = 50, int currentBatch = 1)
        {
            Dictionary <string, string> criteriaX = new Dictionary <string, string>()
            {
                ["FileName"] = fileName
            };

            MyDbUtils mdu      = new MyDbUtils(this.DbPath);
            DataTable resultDT = mdu.LoadEntries(tableName: "OutboundStrEmails", orderBy: "Phase", perBatch: perBatch, currentBatch: currentBatch, criteria: criteriaX);


            return(resultDT);
        }
Beispiel #4
0
        /// <summary>
        /// Load an entry based from a given FileName
        /// </summary>
        /// <param name="targetFile"></param>
        /// <param name="perBatch"></param>
        /// <param name="currentBatch"></param>
        public DataTable LoadFileNameAndPhaseFromDb(string targetFile, string targetPhase, int perBatch = 50, int currentBatch = 1)
        {
            Dictionary <string, string> innerC = new Dictionary <string, string>()
            {
                ["FileName"] = targetFile,
                ["Phase"]    = targetPhase
            };

            Dictionary <string, string> outerC = new Dictionary <string, string>()
            {
                ["FileName"] = targetFile,
                ["Phase"]    = targetPhase
            };

            MyDbUtils mdu = new MyDbUtils(this.DbPath);

            return(mdu.LoadEntriesViaSubquery(TABLE_NAME, perBatch, currentBatch, targetColumn: "FileName", innerCriteria: innerC, outerCriteria: outerC, outerOrderBy: "Phase"));
        }
        /// <summary>
        /// Insert entry if non existent otherwise update entry
        /// </summary>
        public void InsertToDb()
        {
            Dictionary <string, string> criteriaX = new Dictionary <string, string>()
            {
                ["FileName"]      = this.FileName,
                ["EmailUsername"] = this.EmailUsername,
            };
            MyDbUtils mduForCount = new MyDbUtils(this.DbPath);
            long      resultCount = mduForCount.CountEntries(TABLE_NAME, criteriaX);

            if (resultCount < 1)
            {
                Dictionary <string, string> recordsX = new Dictionary <string, string>()
                {
                    ["FileName"]      = this.FileName,
                    ["Subject"]       = this.Subject,
                    ["EmailUsername"] = this.EmailUsername,
                    ["Response"]      = this.Response,
                    ["ResponseDate"]  = this.ResponseDate,
                    ["Phase"]         = this.Phase,
                    ["Inv"]           = this.Inv,
                    ["Message"]       = this.Msg
                };

                MyDbUtils mdu = new MyDbUtils(this.DbPath);
                mdu.CreateEntry(TABLE_NAME, recordsX);
            }
            else
            {
                Dictionary <string, string> recordsX = new Dictionary <string, string>()
                {
                    ["Subject"]      = this.Subject,
                    ["Response"]     = this.Response,
                    ["ResponseDate"] = this.ResponseDate,
                    ["Phase"]        = this.Phase
                };

                MyDbUtils mduForUpdate = new MyDbUtils(this.DbPath);
                mduForUpdate.UpdateEntry(TABLE_NAME, criteriaX, recordsX);
            }
        }
        /// <summary>
        /// Determine approval
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public bool IsApproved(string fileName, int cutOff = 3, string inv = "")
        {
            string    phaseX = GetCurrentPhaseViaFileName(fileName);
            MyDbUtils mdu    = new MyDbUtils(this.DbPath);
            Dictionary <string, string> countCritX = new Dictionary <string, string>()
            {
                ["FileName"] = fileName,
                ["Phase"]    = phaseX,
                ["Response"] = "APPROVED"
            };

            if (!string.IsNullOrEmpty(inv))
            {
                countCritX["Inv"] = inv.Trim();
            }

            long resultCt = mdu.CountEntries(TABLE_NAME, countCritX);

            Console.WriteLine($"Approval Count >>> {resultCt} | {phaseX}");

            return(resultCt >= cutOff);
        }
        /// <summary>
        /// Determine approval based on majority
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        //public bool IsDisapproved(string fileName)
        //{
        //    string phaseX = GetCurrentPhaseViaFileName(fileName);

        //    StrEmailsRecipientsHandler strRecipientsH = new StrEmailsRecipientsHandler(this.DbPath);
        //    DataTable IsAvailableDt = strRecipientsH.LoadFromDbIsAvailable(phaseX);
        //    Double IsAvailableCount = IsAvailableDt.AsEnumerable().Count();
        //    Double cutOff = IsAvailableCount / 2.0;

        //    // Disapproval count
        //    MyDbUtils mdu = new MyDbUtils(this.DbPath);
        //    Dictionary<string, string> countCritX = new Dictionary<string, string>()
        //    {
        //        ["FileName"] = fileName,
        //        ["Phase"] = phaseX,
        //        ["Response"] = "REJECTED"
        //    };
        //    Double resultCt = mdu.CountEntries(TABLE_NAME, countCritX);

        //    // Overall count of responses
        //    MyDbUtils mduY = new MyDbUtils(this.DbPath);
        //    Dictionary<string, string> countCritY = new Dictionary<string, string>()
        //    {
        //        ["FileName"] = fileName,
        //        ["Phase"] = phaseX,
        //    };
        //    Double overallCt = mduY.CountEntries(TABLE_NAME, countCritY);


        //    if (overallCt < cutOff) // not enuf respondents
        //    {
        //        return false; // dont label as disapproved
        //    }

        //    if (resultCt == 0) // non existing filename
        //    {
        //        return false;
        //    }
        //    return resultCt >= cutOff;  // True if REJECTED count is more than the cutOff count
        //}



        /// <summary>
        /// Determine approval if 3 or more REJECTED
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public bool IsDisapproved(string fileName, int cutOff = 3)
        {
            string phaseX = GetCurrentPhaseViaFileName(fileName);

            // Disapproval count
            MyDbUtils mdu = new MyDbUtils(this.DbPath);
            Dictionary <string, string> countCritX = new Dictionary <string, string>()
            {
                ["FileName"] = fileName,
                ["Phase"]    = phaseX,
                ["Response"] = "REJECTED"
            };
            Double resultCt = mdu.CountEntries(TABLE_NAME, countCritX);


            if (resultCt >= cutOff) // True if there are 3 or REJECTED
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }