Exemple #1
0
 public NewMail(OldMail oldMail, int _dMail,
                int _uMail, int _iMail, string _remark = null)
 {
     //FormType 3 = LETTERS, MailType 1 = 2017-LetterMail
     MailDate     = oldMail.MailDate;
     AckID        = oldMail.AckNo;
     FormID       = 3;
     MailType     = oldMail.MailType;
     MailTypeID   = 1;
     Pieces       = oldMail.Pieces;
     Postage      = oldMail.Postage;
     DomesticMail = _dMail;
     USMail       = _uMail;
     IntlMail     = _iMail;
     Remark       = _remark;
 }
Exemple #2
0
        //Convert Function from old to new
        public static List <NewMail> FormatSolver(OldMail oldMail)
        {
            List <NewMail> result = new List <NewMail>();
            int            sum;

            //in 2016 domestic rate = 0.74, US rate 1.19, Int'l rate 2.36
            //in 2017 domestic rate = 0.76, US rate 1.19, Int'l rate 2.42

            decimal cr = 0.76M, ur = 1.19M, tr = 2.42M, cost;

            sum  = oldMail.Pieces;
            cost = oldMail.Postage;
            if (sum * cr == cost)
            {
                result.Add(new NewMail(oldMail, sum, 0, 0));
            }
            else if (sum * tr == cost)
            {
                result.Add(new NewMail(oldMail, 0, 0, sum));
            }
            else if (sum * cr < cost)
            {
                //ur>cr && ur<tr, so need to calculate other possibilities
                if (sum * ur == cost)
                {
                    result.Add(new NewMail(oldMail, 0, sum, 0));
                }
                //first loop if there are only 2 values
                for (int i = (sum - 1); i > 0; i--)
                {
                    if (i * cr + (sum - i) * ur == cost)
                    {
                        result.Add(new NewMail(oldMail, i, sum - i, 0));
                    }
                    else if (i * cr + (sum - i) * tr == cost)
                    {
                        result.Add(new NewMail(oldMail, i, 0, sum - i));
                    }
                    else if (i * ur + (sum - i) * tr == cost)
                    {
                        result.Add(new NewMail(oldMail, 0, i, sum - i));
                    }
                    else
                    {
                        //second loop if there are 3 valid values
                        for (int j = (i - 1); j > 0; j--)
                        {
                            if (j * cr + (i - j) * ur + (sum - i) * tr == cost)
                            {
                                result.Add(new NewMail(oldMail, j, i - j, sum - i));
                            }
                        }
                    }
                }
            }
            else
            {
                result.Add(new NewMail(oldMail, 0, 0, 0, "Invalid Data"));
            }

            if (result.Count < 1)
            {
                result.Add(new NewMail(oldMail, 0, 0, 0, "Invalid Data"));
            }
            else if (result.Count > 1)
            {
                foreach (var mail in result)
                {
                    mail.Remark = "Multiple Results";
                }
            }
            return(result);
        }