Пример #1
0
        private ErrorCL resendServHuv(string ident)
        {
            ErrorCL err = new ErrorCL();

            err.ErrCode    = 0;
            err.ErrMessage = "";

            ServHuvCL sh  = new ServHuvCL();
            CMServHuv csh = new CMServHuv();

            sh.Vart_ordernr = vart_ordernr;
            sh = csh.getServiceHuvud(sh, ident);
            if (sh.ErrCode != 0)
            {
                err.ErrCode    = sh.ErrCode;
                err.ErrMessage = sh.ErrMessage;
                return(err);
            }
            err = pyrExp.exportOrder(sh);
            return(err);
        }
Пример #2
0
        /// <summary>
        /// Validate, insert or update one servicehuvud
        /// </summary>
        /// <param name="sh"></param>
        /// <param name="ident"></param>
        /// <returns>Newly created servicehuvud</returns>
        // 2018-01-29 KJBO
        public ServHuvCL saveServHuv(ServHuvCL sh, string ident)
        {
            log.log("saveServHuv startas", "0");

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

            if (identOK == -1)
            {
                shc.ErrCode    = -10;
                shc.ErrMessage = "Ogiltigt login";
                return(shc);
            }
            log.log("Efter koll av identitet", "0");

            ReparatorCL repIdent = cr.getReparator(ident);

            if (sh.OrderAdmin.Length == 0)
            {
                shc.ErrCode    = -6;
                shc.ErrMessage = "Orderadministratör måste väljas";
                log.log("Orderadministratör måste väljas", "0");
                return(shc);
            }

            ReparatorCL rep = cr.getReparatorFromID(sh.OrderAdmin);

            if (rep == null)
            {
                shc.ErrCode    = -2;
                shc.ErrMessage = "Felaktig orderadmin";
                log.log("Felaktig admin", "0");
                return(shc);
            }

            if (sh.Vart_ordernr.Length == 0)
            {
                shc.ErrCode    = -3;
                shc.ErrMessage = "Vårt ordernummer måste anges";
                return(shc);
            }

            if (sh.Ert_ordernr.Length == 0)
            {
                shc.ErrCode    = -4;
                shc.ErrMessage = "Ert ordernummer måste anges";
                return(shc);
            }

            if (sh.Kund == "")
            {
                shc.ErrCode    = -5;
                shc.ErrMessage = "Kund måste väljas";
                return(shc);
            }

            string ErrTxt = "";
            int    rc     = validateServHuv(sh, ref ErrTxt);

            log.log("ValidateServHuv returnerar : " + rc.ToString(), "");
            if (ErrTxt != "")
            {
                shc.ErrCode    = -101;
                shc.ErrMessage = ErrTxt;
                log.log("Feltext från validateServHuv " + ErrTxt, "0");
                return(shc);
            }
            if (rc == -1)
            {
                shc.ErrCode    = -7;
                shc.ErrMessage = "Vårt ordernummer används redan i systemet";
                return(shc);
            }

            if (sh.FromDate > sh.ToDate)
            {
                shc.ErrCode    = -8;
                shc.ErrMessage = "Felaktigt datumintervall";
                return(shc);
            }

            CExportToPyramid expPyr = new CExportToPyramid();

            if (CConfig.sendToPyramid == 1)
            {
                shc.ErrMessage = expPyr.checkPyramidAPIAvailable();
                if (shc.ErrMessage != "")
                {
                    shc.ErrCode = -1305;
                    if (shc.ErrMessage.Length > 2000)
                    {
                        shc.ErrMessage = shc.ErrMessage.Substring(1, 2000);
                    }
                    return(shc);
                }
            }
            string sSql = "";

            if (sh.IsNew)
            {
                sSql = getInsertSQL();
            }
            else
            {
                sSql = getUpdateSQL();
            }
            NxParameterCollection np = new NxParameterCollection();

            setParameters(np, sh, repIdent.AnvID);
            log.log("Efter set parameters ", "0");
            string errText = "";
            int    iRc     = cdb.updateData(sSql, ref errText, np);

            log.log("Feltext från updateData " + errText, "0");
            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                shc.ErrCode    = -100;
                shc.ErrMessage = errText;
                return(shc);
            }

            iRc = saveWeeks(sh, repIdent.AnvID, ref errText);
            log.log("SaveWeeks returnerar " + iRc.ToString(), "0");
            if (iRc != 1)
            {
                shc.ErrCode    = -100;
                shc.ErrMessage = errText;
                return(shc);
            }
            string godkand = "N";

            if (sh.Godkand)
            {
                godkand = "J";
            }
            log.log("Godkänd är " + godkand, "0");
            if (sh.Godkand)
            {
                CTidRed ctr = new CTidRed();
                ctr.closeAllWeeksForOrder(sh.Vart_ordernr);
            }
            log.log("Före sendToPyramid", "0");
            log.log("sentToPyramid returnerar " + CConfig.sendToPyramid.ToString(), "0");

            if (CConfig.sendToPyramid == 1 && shallSendToPyramid(sh.Vart_ordernr))
            {
                ErrorCL errCl = null;
                log.log("Före  exportToPyramid", "0");
                errCl = expPyr.exportOrder(sh);
                log.log("Efter  exportToPyramid", "0");


                if (errCl.ErrCode != 0)
                {
                    shc.ErrCode    = errCl.ErrCode;
                    shc.ErrMessage = errCl.ErrMessage;
                    return(shc);
                }


                // 2018-05-17
                if (sh.Godkand && isPyramidOrder(sh.Vart_ordernr))
                {
                    // 2018-11-09
                    // To be sure that all possible errors when creating reservation to Pyramid
                    // is handled and resent if possible
                    errCl = expPyr.ensureOrderArtIsReserved(sh.Vart_ordernr);
                    if (errCl.ErrCode != 0)
                    {
                        shc.ErrCode    = errCl.ErrCode;
                        shc.ErrMessage = errCl.ErrMessage;
                        return(shc);
                    }

                    errCl = expPyr.exportTime(sh.Vart_ordernr);
                    if (errCl.ErrCode != 0)
                    {
                        shc.ErrCode    = errCl.ErrCode;
                        shc.ErrMessage = errCl.ErrMessage;
                        return(shc);
                    }


                    errCl = expPyr.exportReservdel(sh.Vart_ordernr);
                    if (errCl.ErrCode != 0)
                    {
                        shc.ErrCode    = errCl.ErrCode;
                        shc.ErrMessage = errCl.ErrMessage;
                        return(shc);
                    }

                    errCl = expPyr.exportReservdelKat1(sh.Vart_ordernr);
                    if (errCl.ErrCode != 0)
                    {
                        shc.ErrCode    = errCl.ErrCode;
                        shc.ErrMessage = errCl.ErrMessage;
                        return(shc);
                    }
                }

                expPyr.setOrderStatus(sh.Vart_ordernr);
                int newStatus = sh.Godkand ? 1 : 0;
                expPyr.addToPyramidChange(sh.Vart_ordernr, repIdent.AnvID, newStatus);
                resendToPyramid();
            }


            if (sh.IsNew)
            {
                CServRad csr = new CServRad();

                string err = csr.createFirstRow(sh.Vart_ordernr, sh.Kund);
                if (err != "")
                {
                    shc.ErrCode    = -1201;
                    shc.ErrMessage = err;
                    return(shc);
                }
            }


            ServHuvCL shRet = getServiceHuvud(sh, ident);

            log.log("getServiceHuvud har meddelande " + shRet.ErrMessage, "0");
            return(shRet);
        }