private string GetTimeCode(string psTime, bool isDel = false)
        {
            string lsCode = "";

            using (SCT db = new SCT())
            {
                TimeCodeMap tcm = db.TimeCodeMaps.Where(p => p.TimeVal == psTime).FirstOrDefault();

                if (tcm != null)
                {
                    if (isDel)
                    {
                        lsCode = tcm.TimeCode_DEL.GetValueOrDefault(0).ToString();
                    }
                    else
                    {
                        lsCode = tcm.TimeCode.GetValueOrDefault(0).ToString();
                    }

                    if (lsCode.Length < 2)
                    {
                        lsCode = "0" + lsCode;
                    }
                }
            }

            return(lsCode);
        }
Exemplo n.º 2
0
 public static void LogError(string psMessage, string psModule, Int32 piShipReqID = 0)
 {
     try {
         ShippingRequestError E = new ShippingRequestError();// new ShippingRequestError();
         E.DateCreated = System.DateTime.Now;
         E.Module      = psModule;
         E.ErrorDetail = psMessage;
         E.ShipReqID   = piShipReqID;
         using (SCT db = new SCT()) {
             db.ShippingRequestErrors.Add(E);
             db.SaveChanges();
         }
     } catch (Exception e)
     {
         LogErrorRaw("Error occurred when logging an error.  Original error: " + psModule + ": " + psMessage + " : " + e.ToString(), "Log.LogError");
     }
 }
Exemplo n.º 3
0
    public static double[] ciqf(int nt, double[] t, int[] mlt, int nwts, ref int[] ndx, int key,
                                int kind, double alpha, double beta, double a, double b, int lo)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CIQF computes weights for a classical weight function and any interval.
    //
    //  Discussion:
    //
    //    This routine compute somes or all the weights of a quadrature formula
    //    for a classical weight function with any valid A, B and a given set of
    //    knots and multiplicities.
    //
    //    The weights may be packed into the output array WTS according to a
    //    user-defined pattern or sequentially.
    //
    //    The routine will also optionally print knots and weights and a check
    //    of the moments.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 January 2010
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky.
    //    C++ version by John Burkardt.
    //
    //  Reference:
    //
    //    Sylvan Elhay, Jaroslav Kautsky,
    //    Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of
    //    Interpolatory Quadrature,
    //    ACM Transactions on Mathematical Software,
    //    Volume 13, Number 4, December 1987, pages 399-415.
    //
    //  Parameters:
    //
    //    Input, int NT, the number of knots.
    //
    //    Input, double T[NT], the knots.
    //
    //    Input, int MLT[NT], the multiplicity of the knots.
    //
    //    Input, int NWTS, the number of weights.
    //
    //    Input/output, int NDX[NT], used to index the output
    //    array WTS.  If KEY = 1, then NDX need not be preset.  For more
    //    details see the comments in CAWIQ.
    //
    //    Input, int KEY, indicates the structure of the WTS
    //    array.  It will normally be set to 1.  This will cause the weights to be
    //    packed sequentially in array WTS.  For more details see the comments
    //    in CAWIQ.
    //
    //    Input, int KIND, the rule.
    //    1, Legendre,             (a,b)       1.0
    //    2, Chebyshev Type 1,     (a,b)       ((b-x)*(x-a))^(-0.5)
    //    3, Gegenbauer,           (a,b)       ((b-x)*(x-a))^alpha
    //    4, Jacobi,               (a,b)       (b-x)^alpha*(x-a)^beta
    //    5, Generalized Laguerre, (a,+oo)     (x-a)^alpha*exp(-b*(x-a))
    //    6, Generalized Hermite,  (-oo,+oo)   |x-a|^alpha*exp(-b*(x-a)^2)
    //    7, Exponential,          (a,b)       |x-(a+b)/2.0|^alpha
    //    8, Rational,             (a,+oo)     (x-a)^alpha*(x+b)^beta
    //    9, Chebyshev Type 2,     (a,b)       ((b-x)*(x-a))^(+0.5)
    //
    //    Input, double ALPHA, the value of Alpha, if needed.
    //
    //    Input, double BETA, the value of Beta, if needed.
    //
    //    Input, double A, B, the interval endpoints.
    //
    //    Input, int LO, selects the actions to perform.
    //     > 0, compute and print weights.  Print moments check.
    //     = 0, compute weights.
    //     < 0, compute and print weights.
    //
    //    Output, double CIQF[NWTS], the weights.
    //
    {
        int j;

        int m = 1;
        int l = Math.Abs(key);

        for (j = 0; j < nt; j++)
        {
            if (l == 1 || Math.Abs(ndx[j]) != 0)
            {
                m += mlt[j];
            }
        }

        if (nwts + 1 < m)
        {
            Console.WriteLine("");
            Console.WriteLine("CIQF - Fatal error!");
            Console.WriteLine("  NWTS + 1 < M.");
            return(null);
        }

        int mex = 2 + m;

        //
        //  Scale the knots to default A, B.
        //
        double[] st = SCT.sct(nt, t, kind, a, b);
        //
        //  Compute the weights.
        //
        const int lu = 0;

        double[] wts = CIQFS.ciqfs(nt, st, mlt, nwts, ref ndx, key, kind, alpha, beta, lu);
        //
        //  Don't scale user's knots - only scale weights.
        //
        SCQF.scqf(nt, st, mlt, wts, nwts, ndx, ref wts, ref st, kind, alpha, beta, a, b);

        if (lo == 0)
        {
            return(wts);
        }

        int mop = m - 1;

        CHKQF.chkqf(t, wts, mlt, nt, nwts, ndx, key, mop, mex, kind,
                    alpha, beta, lo, a, b);

        return(wts);
    }
        public bool Process(out string psMessages)
        {
            bool lbResult = true;

            psMessages = "";


            try

            {
                string strUserName = Util.GetString(ConfigurationManager.AppSettings["SAPUserName"]);
                string strPassword = Util.GetString(ConfigurationManager.AppSettings["SAPUserPassword"]);

                if (strUserName == "")
                {
                    strUserName = "******";
                }

                if (strPassword == "")
                {
                    strPassword = "******";
                }

                if (strUserName == "" || strPassword == "")
                {
                    Log.LogError("Failed to get sap username and or password", "OrderImportClasses.ProcessOrders");
                    psMessages = "Failed to get sap username and or password";
                    return(false);
                }

                List <ShippingRequestHeader> headerList;

                using (SCT hdb = new SCT())
                {
                    headerList = (from p in hdb.ShippingRequestHeaders where p.ProcessedDate == null select p).ToList();
                }

                if (headerList.Count > 0)
                {
                    SCTWS.zsd_create_web_so ws = new SCTWS.zsd_create_web_so();
                    ws.Timeout = 60000;
                    ws.Url     = ws.Url + "?ts=" + System.DateTime.Now.ToString("yyyyMMddHHmmss");
                    NetworkCredential netCredential = new NetworkCredential(strUserName, strPassword);
                    Uri          uri         = new Uri(ws.Url);
                    ICredentials credentials = netCredential.GetCredential(uri, "Basic");
                    ws.Credentials = credentials;

                    foreach (ShippingRequestHeader h in headerList)
                    {
                        string lsMessage = "";

                        if (!ProcessHeader(ws, h.ShipReqID, out lsMessage))
                        {
                            SendErrorEmails(lsMessage, h);
                            lbResult = false;
                        }

                        psMessages = string.Concat(psMessages, psMessages == "" ? "" : System.Environment.NewLine, "Processed Header ", h.ShipReqID.ToString(), " ", lsMessage);
                    }
                }
                else
                {
                    psMessages = "No unprocessed headers found.";
                }
            }

            catch (Exception ex)
            {
                Log.LogError(ex.ToString(), "OrderImportClasses.ProcessOrders");
                psMessages = ex.ToString();
                lbResult   = false;
            }

            return(lbResult);
        }
        private bool ProcessHeader(SCTWS.zsd_create_web_so poWS, Int32 piShipReqID, out string psMessage)
        {
            bool lbResult = true;

            psMessage = "";

            string lsMessage = "";

            SCT db = new SCT();

            try {
                List <ShippingRequestDetail> itemList = null;
                ShippingRequestHeader        h        = db.ShippingRequestHeaders.Find(piShipReqID);
                h.ProcessedDate = System.DateTime.Now;
                db.SaveChanges();

                itemList = (from p in db.ShippingRequestDetails where p.ShipReqID == piShipReqID select p).ToList();

                if (itemList != null && itemList.Count > 0)
                {
                    string lsSAPOrderNumber = "";

                    ZSD_CREATE_WEB_SALES_ORDER so = new ZSD_CREATE_WEB_SALES_ORDER();

                    so.IS_SO_HEADER = new ZSD_WEB_SO_HEADER_S();

                    ZSD_WEB_SO_HEADER_S header = so.IS_SO_HEADER;
                    header.BSTKD   = Util.GetString(h.CustomerPONum);
                    header.BSTKD_E = Util.GetString(h.ConsignmentRef);
                    header.TEMP    = Util.GetString(h.TemperatureID);
                    header.TRATY   = Util.GetString(h.MeansOfTransportID);
                    header.KUNAG   = Util.GetString(h.CustomerAccountID);
                    header.SHIPFR  = Util.GetString(h.PickupFromID);
                    header.BSTDK   = Util.GetString(h.PickupDate.ToString("yyyy-MM-dd"));
                    header.PICKUP  = GetTimeCode(Util.GetString(h.PickupTime), false);

                    if (header.PICKUP == "")
                    {
                        lsMessage = "Unable to resolve PICKUP time code for " + Util.GetString(h.PickupTime);
                        Log.LogError(lsMessage, "OrderImportClasses.ProcessOrder", piShipReqID);
                        return(false);
                    }

                    header.SHIPTO = Util.GetString(h.DeliverToID);
                    header.VDATU  = Util.GetString(h.DeliveryDate.ToString("yyyy-MM-dd"));
                    header.DELCO  = GetTimeCode(Util.GetString(h.DeliveryTime), true);

                    if (header.DELCO == "")
                    {
                        psMessage = "Unable to resolve DELCO time code for " + Util.GetString(h.DeliveryTime);
                        Log.LogError(psMessage, "OrderImportClasses.ProcessOrder", piShipReqID);
                        return(false);
                    }

                    header.DELIV_INSTR = Util.GetString(h.DeliveryInstructions);

                    List <ZSD_WEB_SO_ITEM_S> items = new List <ZSD_WEB_SO_ITEM_S>();

                    foreach (ShippingRequestDetail i in itemList)
                    {
                        ZSD_WEB_SO_ITEM_S item = new ZSD_WEB_SO_ITEM_S();
                        item.BRGEW  = Util.GetDecimal(i.GrossWeight);
                        item.KWMENG = Util.GetDecimal(i.Quantity);
                        item.MATNR  = Util.GetString(i.MaterialNumber);
                        item.MEINS  = Util.GetString(i.UnitOfMeasure);
                        item.NTGEW  = Util.GetDecimal(i.NetWeight);
                        item.VOLUM  = Util.GetDecimal(i.Volume);
                        items.Add(item);
                    }

                    so.IT_SO_ITEM = items.ToArray();

                    List <BAPIRET2> retlist = new List <BAPIRET2>();

                    BAPIRET2 bret = new BAPIRET2();

                    retlist.Add(bret);
                    so.ET_RETURN = retlist.ToArray();

                    ZSD_CREATE_WEB_SALES_ORDERResponse ret = null;

                    try
                    {
                        // Log.LogError("Pre send web request", "OrderImportClasses.ProcessOrders");
                        ret = poWS.ZSD_CREATE_WEB_SALES_ORDER(so);
                        // Log.LogError("Post send web request", "OrderImportClasses.ProcessOrders");
                        if (ret != null && ret.ET_RETURN != null && ret.ET_RETURN.Length > 0)
                        {
                            for (int i = 0; i < ret.ET_RETURN.Length; i++)
                            {
                                BAPIRET2 returnLine  = ret.ET_RETURN[i];
                                string   allMessages = returnLine.MESSAGE + " " +
                                                       returnLine.MESSAGE_V1 + " " +
                                                       returnLine.MESSAGE_V2 + " " +
                                                       returnLine.MESSAGE_V3 + " " +
                                                       returnLine.MESSAGE_V4;

                                if (returnLine.TYPE.ToUpper() != "S")
                                {
                                    lbResult   = false;
                                    psMessage += " " + allMessages;
                                }
                                else
                                {
                                    if (returnLine.NUMBER == "311")
                                    {
                                        allMessages = allMessages.ToLower();
                                        int start = allMessages.IndexOf("booking request");
                                        allMessages      = allMessages.Substring(start + "booking request".Length + 1);
                                        start            = allMessages.IndexOf("has been saved");
                                        lsSAPOrderNumber = allMessages.Substring(0, start).Trim();
                                    }
                                }
                            }
                        }
                        else
                        {
                            psMessage += "No return data from web service.";
                            lbResult   = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        psMessage = ex.ToString();
                        lbResult  = false;
                    }


                    if (lbResult)
                    {
                        h.SAPOrderNumber = lsSAPOrderNumber;
                        psMessage       += " created order " + lsSAPOrderNumber;
                    }
                    else
                    {
                        h.SAPOrderNumber = "";

                        Log.LogError("Failed to create Sales Request Header. " + psMessage + " Customer ID = " + so.IS_SO_HEADER.KUNAG + "; Order No = " + so.IS_SO_HEADER.BSTDK,
                                     "OrderImportClasses.ProcessOrder", h.ShipReqID);
                    }

                    h.ProcessedSuccessfully = lbResult;
                    h.UpdateDate            = System.DateTime.Now;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Log.LogError(e.ToString(), "ProcessOrders.ProcessOrder", piShipReqID);
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return(lbResult);
        }