示例#1
0
        /// <summary>
        /// Saves a reservdel to database.
        /// If ReservNr = 0 then the method
        /// assumes that this is a new row to be added
        /// Otherwise an update is issued
        /// </summary>
        /// <param name="ident">Identity</param>
        /// <param name="reservdel">ReservdelCL</param>
        /// <returns>The new created or updated reservdel</returns>
        //  2016-02-10 KJBO
        public ReservdelCL saveReservdel(string ident, ReservdelCL reservdel)
        {
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            ReservdelCL retRes = new ReservdelCL();

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

            // Validate that order is open for editing
            CServiceHuvud ch    = new CServiceHuvud();
            string        sOpen = ch.isOpen(ident, reservdel.VartOrdernr);

            if (sOpen != "1")
            {
                {
                    retRes.ErrCode = -10;
                    if (sOpen == "-1")
                    {
                        retRes.ErrMessage = "Order är stängd för inmatning";
                    }
                    else
                    {
                        retRes.ErrMessage = sOpen;
                    }
                    return(retRes);
                }
            }


            int valid = validateReservdel(reservdel);

            if (valid == -1)
            {
                retRes.ErrCode    = -1;
                retRes.ErrMessage = "Felaktig serviceorder";
                return(retRes);
            }
            if (valid == -10)
            {
                retRes.ErrCode    = -1;
                retRes.ErrMessage = "Fel vid kontroll av reservdel";
                return(retRes);
            }

            if (valid == -2)
            {
                retRes.ErrCode    = -1;
                retRes.ErrMessage = "Reservdel finns inte";
                return(retRes);
            }

            if (valid == -3)
            {
                retRes.ErrCode    = -1;
                retRes.ErrMessage = "Egen reservdel måste ha en benämning";
                return(retRes);
            }

            if (valid == -4)
            {
                retRes.ErrCode    = -1;
                retRes.ErrMessage = "Det finns ingen reservdel på ordernr : " + reservdel.VartOrdernr + "rad : " + reservdel.Radnr.ToString() + " reservdelsrad : " + reservdel.ReservNr.ToString();
                return(retRes);
            }

            string sSql    = "";
            string errText = "";
            int    errCode = 0;

            // This is a new reservdel
            if (reservdel.ReservNr == 0)
            {
                reservdel.ReservNr = getNextReservNr(reservdel);
                sSql = getInsertSQL();
            }
            else
            {
                sSql = getUpdateSQL();
            }


            AddOrDeleteReservdelPyr(reservdel, true, ref errText);
            ReparatorCL           rep = cr.getReparator(ident);
            NxParameterCollection np  = new NxParameterCollection();

            setParameters(np, reservdel, rep.AnvID);

            int iRc = cdb.updateData(sSql, ref errText, np);


            if (errText == "")
            {
                AddOrDeleteReservdelPyr(reservdel, false, ref errText);
                if (errText != "")
                {
                    errText = "Fel vid anrop till addToReservdelPyr. Felmeddelande : " + errText;
                    errCode = -1303;
                }
            }
            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                if (errCode == 0)
                {
                    retRes.ErrCode = -100;
                }
                else
                {
                    retRes.ErrCode = errCode;
                }
                retRes.ErrMessage = errText;
                return(retRes);
            }

            // 2018-05-17 KJBO Check if this is a pyramidOrder
            CMServHuv shuv = new CMServHuv();

            if (shuv.isPyramidOrder(reservdel.VartOrdernr))
            {
                ErrorCL errCl = checkOutIfNeeded(ident, reservdel);
                if (errCl.ErrMessage != "")
                {
                    if (errText.Length > 2000)
                    {
                        errText = errText.Substring(1, 2000);
                    }

                    retRes.ErrCode    = errCl.ErrCode;
                    retRes.ErrMessage = errCl.ErrMessage;
                    return(retRes);
                }



                CompactStore.CCompactStore store = new CompactStore.CCompactStore();
                errCl = store.genCompStoreData(ident, reservdel.VartOrdernr);
                if (errCl.ErrMessage != "" && errCl.ErrCode != 1)
                {
                    if (errText.Length > 2000)
                    {
                        errText = errText.Substring(1, 2000);
                    }

                    retRes.ErrCode    = errCl.ErrCode;
                    retRes.ErrMessage = errCl.ErrMessage;
                    return(retRes);
                }
            }



            return(getReservdel(ident, reservdel.VartOrdernr, reservdel.Radnr, reservdel.ReservNr));
        }
示例#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)
        {
            CMServHuv cms = new CMServHuv();

            return(cms.saveServHuv(sh, ident));
        }
示例#3
0
        /// <summary>
        /// Identifies a servicehuvud by sh.vart_ordernr
        /// Retrieves the matching order and return
        /// </summary>
        /// <param name="sh"></param>
        /// <param name="ident"></param>
        /// <returns></returns>

        public ServHuvCL getServiceHuvud(ServHuvCL sh, string ident)
        {
            CMServHuv cms = new CMServHuv();

            return(cms.getServiceHuvud(sh, ident));
        }
示例#4
0
        /// <summary>
        /// Returns a list of momskoder
        /// This is used by Pyramid
        /// </summary>
        /// <param name="ident"></param>
        /// <returns></returns>
        /// 2018-04-27 KJBO Indentive AB
        public List <MomskodCL> getMomskoder(string ident)
        {
            CMServHuv sh = new CMServHuv();

            return(sh.getMomskoder(ident));
        }
示例#5
0
        /// <summary>
        /// Calculate the next available order number is this is numeric
        /// Otherwise returns an empty string
        /// </summary>
        /// <returns></returns>
        /// 2018-04-26 KJBO Indentive AB
        public string getNextOrderNumber()
        {
            CMServHuv sh = new CMServHuv();

            return(sh.getNextOrderNumber());
        }
示例#6
0
        /// <summary>
        /// Updates the AllRep flag on an order
        /// (This flag indicates that all reparators
        /// can log in. The normal process is that
        /// there is a list (in the shReparator table) with
        /// the reparators that can log in on a certain order).
        /// </summary>
        /// <param name="VartOrdernr"></param>
        /// <param name="allRep"></param>
        /// <param name="ident"></param>
        /// <returns></returns>
        /// 2018-02-08 KJBO
        public ServHuvCL updateAllRep(string VartOrdernr, bool allRep, string ident)
        {
            CMServHuv cmsh = new CMServHuv();

            return(cmsh.updateAllRep(VartOrdernr, allRep, ident));
        }