Example #1
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)
        {
            ServHuvCL   shc      = new ServHuvCL();
            CReparator  cr       = new CReparator();
            ReparatorCL repIdent = cr.getReparator(ident);


            string sSql = " update servicehuvud "
                          + " set AllRep = :AllRep "
                          + " where vart_ordernr = :vart_ordernr ";
            NxParameterCollection np = new NxParameterCollection();

            np.Add("AllRep", allRep);
            np.Add("vart_ordernr", VartOrdernr);

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

            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                shc.ErrCode    = -100;
                shc.ErrMessage = errText;
                return(shc);
            }
            shc.Vart_ordernr = VartOrdernr;
            return(getServiceHuvud(shc, ident));
        }
Example #2
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));
        }
Example #3
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);
        }
Example #4
0
        public ReparatorCL getReparator(string ident)
        {
            CReparator cr = new CReparator();

            return(cr.getReparator(ident));
        }
Example #5
0
        /// <summary>
        /// Updates the table shReparator.
        /// If the parameter addTo order then a new row will be added
        /// with the current ordernr and AnvId
        /// if false then the row is deleted
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="VartOrdernr"></param>
        /// <param name="AnvID"></param>
        /// <param name="addToOrder"></param>
        /// <returns></returns>
        /// 2018-02-05  KJBO
        public ErrorCL updateShrep(string ident, string VartOrdernr, string AnvID, Boolean addToOrder)
        {
            ErrorCL err = new ErrorCL();

            err.ErrCode    = 0;
            err.ErrMessage = "";
            string sSql = "";
            NxParameterCollection pc = new NxParameterCollection();

            pc.Add("vart_ordernr", VartOrdernr);
            pc.Add("AnvID", AnvID);
            if (addToOrder)
            {
                sSql = "select count(*) antal "
                       + " from shReparator "
                       + " where vart_ordernr = :vart_ordernr "
                       + " and AnvID = :AnvID ";


                DataTable dtCount = cdb.getData(sSql, ident, ref err, pc);

                if (err.ErrMessage != "")
                {
                    return(err);
                }
                int antal = 0;
                if (dtCount.Rows.Count == 1)
                {
                    antal = Convert.ToInt32(dtCount.Rows[0]["antal"]);
                }

                if (antal == 0)
                {
                    sSql = "insert into shReparator (vart_ordernr, AnvID, reg, regdat) "
                           + " values(:vart_ordernr, :AnvID, :reg, :regdat); ";


                    CReparator  cr  = new CReparator();
                    ReparatorCL rep = cr.getReparator(ident);

                    pc.Add("reg", rep.AnvID);
                    pc.Add("regdat", DateTime.Now);

                    string errTxt = "";
                    cdb.updateData(sSql, ref errTxt, pc);

                    if (errTxt != "")
                    {
                        errTxt = "Error while inserting row in shReparator table. Error message : " + errTxt;
                        if (errTxt.Length > 2000)
                        {
                            errTxt = errTxt.Substring(1, 2000);
                        }
                        err.ErrCode    = -100;
                        err.ErrMessage = errTxt;
                        return(err);
                    }
                }
            }
            else
            {
                sSql = " delete from shReparator "
                       + " where vart_ordernr = :vart_ordernr "
                       + " and AnvID = :AnvID ";

                string errTxt = "";
                cdb.updateData(sSql, ref errTxt, pc);

                if (errTxt != "")
                {
                    errTxt = "Error while inserting row in shReparator table. Error message : " + errTxt;
                    if (errTxt.Length > 2000)
                    {
                        errTxt = errTxt.Substring(1, 2000);
                    }
                    err.ErrCode    = -100;
                    err.ErrMessage = errTxt;
                    return(err);
                }
            }
            return(err);
        }
Example #6
0
        public VentilCL saveVentil(string ident, VentilCL v)
        {
            VentilCL   vc      = new VentilCL();
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

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

            // 2018-11-09 Samtal med Simon

            if (v.Position == "")
            {
                vc.ErrCode    = -1;
                vc.ErrMessage = "Positionsnr måste anges";
                return(vc);
            }

            int iRes = validateVentil(v);

            if (iRes == -1)
            {
                vc.ErrCode    = -1;
                vc.ErrMessage = "Felaktig ventilkategori";
                return(vc);
            }
            if (iRes == -2)
            {
                vc.ErrCode    = -1;
                vc.ErrMessage = "Felaktigt kundID";
                return(vc);
            }

            if (iRes == -3)
            {
                vc.ErrCode    = 101;
                vc.ErrMessage = "Det finns redan en ventil med detta positionsnr";
                return(vc);
            }

            if (iRes == -4)
            {
                vc.ErrCode    = -1;
                vc.ErrMessage = "Ytterdiameter måste vara större än innerdiameter";
                return(vc);
            }

            ReparatorCL r = cr.getReparator(ident);



            string sSql = "";
            bool   bNew = false;

            // This is a new ventil
            if (v.VentilID == null)
            {
                string ventilID = Guid.NewGuid().ToString();
                v.VentilID = ventilID;
                sSql       = getVentilInsertSQL();
                bNew       = true;
            }

            else
            {
                sSql = getVentilUpdateSQL();
            }


            NxParameterCollection np = new NxParameterCollection();

            setParameters(np, v, bNew, r.AnvID);

            string errText = "";

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

            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }

                v.ErrCode    = -100;
                v.ErrMessage = errText;
                return(v);
            }

            // 2016-10-17 KJBO
            CServRad csr = new CServRad();

            csr.updateFromVentil2(v.VentilID);



            return(getVentil(ident, v.VentilID));
        }