Exemplo n.º 1
0
        /// <summary>
        /// When recreating reservation for "products in stock" = orderArt
        /// then we need to send "some at the time" because of timouts in
        /// the communication with Pyramid
        /// This means that this function is repetedly called until
        /// the return value total_handled equals to total_count then
        /// all orderArt rows for one order is resent
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="aVart_ordernr"></param>
        /// <param name="noToResend"></param>
        /// <returns></returns>
        public resendOrderArtCL resendxOrderArt(string aVart_ordernr, int noToResend, string ident)
        {
            resendOrderArtCL resend = new resendOrderArtCL();

            resend.ErrCode       = 0;
            resend.ErrMessage    = "";
            resend.total_count   = 0;
            resend.total_handled = 0;
            resend.vartOrdernr   = aVart_ordernr;

            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            if (identOK == -1)
            {
                resend.ErrCode    = -10;
                resend.ErrMessage = "Ogiltigt login";
                return(resend);
            }

            vart_ordernr = aVart_ordernr;


            string sSql = " select orderArtId, coAntal - ciAntal coAntal "
                          + " from orderArt oa "
                          + " where vart_ordernr = :vart_ordernr "
                          + " and not exists(select 'x' "
                          + " from oaPyramid oap "
                          + " where oa.orderArtId = oap.orderArtId "
                          + " and coAntal <> 0) ";
            string error             = "";
            NxParameterCollection pc = new NxParameterCollection();

            pc.Add("vart_ordernr", vart_ordernr);
            DataTable dt = cdb.getData(sSql, ref error, pc);
            int       numberoOfRowsToSend = dt.Rows.Count;

            if (error != "")
            {
                resend.ErrCode    = -36310;
                resend.ErrMessage = "Error when retrieving orderArt to resend. Error message : " + error;
                return(resend);
            }

            int countRows = 0;

            foreach (DataRow dr in dt.Rows)
            {
                int orderArtId = Convert.ToInt32(dr["orderArtId"]);
                int antal      = Convert.ToInt32(dr["coAntal"]);
                error = pyrExp.createReservation(orderArtId, antal);

                // 2019-04-30
                if (error == "Article does not exist." && !CConfig.validateReservation)
                {
                    error = "";
                }


                if (error != "")
                {
                    resend.ErrCode    = -36314;
                    resend.ErrMessage = "Error when creating reservation in Pyramid. Error message : " + error;
                    return(resend);
                }
                countRows++;
                if (countRows == noToResend)
                {
                    break;
                }
            }

            string sSqlCount = " select count(*) countRows "
                               + " from orderArt "
                               + " where vart_ordernr = :vart_ordernr ";

            error = "";
            DataTable dtCount = cdb.getData(sSqlCount, ref error, pc);

            if (error != "")
            {
                resend.ErrCode    = -36312;
                resend.ErrMessage = "Error when counting total orderArt for order. Error message : " + error;
                return(resend);
            }

            resend.total_count   = Convert.ToInt32(dtCount.Rows[0]["countRows"]);
            resend.total_handled = resend.total_count - (numberoOfRowsToSend - countRows);
            return(resend);
        }