Exemple #1
0
        public string updateForraComment(string ventilID, string ovr_komment)
        {
            string sSql = "update ventil "
                          + " set forra_comment = '" + ovr_komment + "' "
                          + " where ventil_id = '" + ventilID + "' ";
            string err = "";

            cdb.updateData(sSql, ref err);
            return(err);
        }
Exemple #2
0
        public int saveWeeks(ServHuvCL sh, string RegBy, ref string ErrText)
        {
            string sSql      = "";
            int    countRows = countTr2Weeks(sh.Vart_ordernr, ref ErrText);

            if (ErrText == "")
            {
                if (countRows == 0)
                {
                    sSql = getWeekInsertSQL();
                }
                else
                {
                    sSql = getWeekUpdateSQL();
                }
                NxParameterCollection np = new NxParameterCollection();
                setWeekParameters(np, sh, RegBy, countRows == 0);

                ErrText = "";
                int iRc = cdb.updateData(sSql, ref ErrText, np);
            }

            if (ErrText != "")
            {
                ErrText = "Error while creating date period " + ErrText;
                if (ErrText.Length > 2000)
                {
                    ErrText = ErrText.Substring(1, 2000);
                }
                return(-100);
            }

            CTidRed ct = new CTidRed();

            ct.createTr2Weeks(sh.Vart_ordernr, sh.FromDate, sh.ToDate, ref ErrText);
            if (ErrText != "")
            {
                ErrText = "Error while creating weeks for period " + ErrText;
                if (ErrText.Length > 2000)
                {
                    ErrText = ErrText.Substring(1, 2000);
                }
                return(-100);
            }

            return(1);
        }
Exemple #3
0
        public void logMessage(int logLevel, string message, string messageDescr = "")
        {
            if (logLevel <= CConfig.devLogLevel)
            {
                string sSql = " insert into devLog (logDate, logLevel, message, messageDescr) "
                              + " values(:logDate, :logLevel, :message, :messageDescr) ";

                NxParameterCollection pc = new NxParameterCollection();
                pc.Add("logDate", DateTime.Now);
                pc.Add("logLevel", logLevel);
                pc.Add("message", message);
                pc.Add("messageDescr", messageDescr);

                string err = "";
                cdb.updateData(sSql, ref err, pc);
            }
        }
Exemple #4
0
        /// <summary>
        /// Deletes a reservdel identified by primary key
        /// </summary>
        /// <param name="ident">identity string</param>
        /// <param name="reservdel">One valid reservdel</param>
        /// <returns>Empty string if OK otherwise error message</returns>
        public string deleteReservdel(string ident, ReservdelCL reservdel)
        {
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            ReservdelCL retRes = new ReservdelCL();

            if (identOK == -1)
            {
                return("Ogiltigt login");
            }

            // 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")
                    {
                        return("Order är stängd för inmatning");
                    }
                    else
                    {
                        return(sOpen);
                    }
                }
            }


            int exists = validateReservdelExists(reservdel);

            if (exists == 0)
            {
                return("Reservdel finns ej");
            }

            string sSql = "";

            sSql = getDeleteSQL();

            NxParameterCollection np = new NxParameterCollection();

            setParameters(np, reservdel, "");

            string errText = "";

            AddOrDeleteReservdelPyr(reservdel, true, ref errText);

            if (errText == "")
            {
                cdb.updateData(sSql, ref errText, np);
            }

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

                return(errText);
            }

            return("");
        }
Exemple #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);
        }
Exemple #6
0
        /// <summary>
        /// Maintains the authenticate table with ValidUntil time
        /// </summary>
        /// <param name="AnvID">AnvandarID</param>
        /// <returns>The current or newly created GUID that the consumer shall use when calling other functions</returns>
        private string UpdateAuthenticate(string AnvID)
        {
            // SQL clause for reading values for the reparator/user
            String sSql = " SELECT anvID, Ident, ValidUntil "
                          + " FROM Authenticate "
                          + " where AnvID = :pAnvID ";
            // Create paramater collection
            NxParameterCollection pc = new NxParameterCollection();

            pc.Add("pAnvID", AnvID);

            string    errSt = "";
            DataTable dt    = cdb.getData(sSql, ref errSt, pc);

            // Get current date and time
            DateTime validUntil = DateTime.Now;

            // Add one day
            validUntil = validUntil.AddDays(1);

            // Add one mor parameter
            pc.Add("pValidUntil", validUntil.ToString());

            // Init variable
            string Ident = "";

            // If there are one entry for the current anvandare
            if (dt.Rows.Count > 0)
            {
                // 2016-02-16 KJBO
                DateTime savedValidUntil = Convert.ToDateTime(dt.Rows[0]["ValidUntil"]);


                if (savedValidUntil < DateTime.Now)
                {
                    Ident = Guid.NewGuid().ToString();
                }
                else
                {
                    Ident = dt.Rows[0]["Ident"].ToString();
                }

                pc.Add("ident", Ident);

                // Update the validUntil (give 24 hours from now)
                sSql = " update Authenticate "
                       + " set validUntil = :pValidUntil "
                       + " , ident = :ident "
                       + " where anvID = :pAnvID ";
                // Update the database
                string errStr = "";
                int    iCount = cdb.updateData(sSql, ref errStr, pc);
            }
            // If no entry exists for the current user then insert a new row
            else
            {
                // Get a new identity (random)
                Ident = Guid.NewGuid().ToString();
                // Add this to a parameter
                pc.Add("pIdent", Ident);

                // Insert clause with parameters
                sSql = " insert into Authenticate (anvId, Ident, ValidUntil) "
                       + " values ( :pAnvID, :pIdent, :pValidUntil) ";

                string errStr = "";
                // Update the database
                int iCount = cdb.updateData(sSql, ref errStr, pc);
            }
            // Return the identity
            return(Ident);
        }
Exemple #7
0
        /// <summary>
        /// Updates the picture metadata.
        /// Note that the picture must exist, identified
        /// by the following properties in the picture class:
        /// VartOrdernr, Radnr, BidlNr.
        /// For performance reason this method does not evaluate
        /// the picture size.
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public PictureCL updatePictMetadata(string ident, PictureCL p)
        {
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            // Creates a class to return an error
            PictureCL pN = new PictureCL();

            if (identOK == -1)
            {
                deletePict(p.PictIdent);
                pN.ErrCode    = -10;
                pN.ErrMessage = "Ogiltigt login";
                return(pN);
            }

            // Init variable
            string err   = "";
            int    valid = validatePicture(p, true, true, ref err);

            if (valid == -1 || valid == -2 || valid == -3)
            {
                pN.ErrCode    = -1;
                pN.ErrMessage = "Kan ej hitta order";
                return(pN);
            }
            if (valid == -4)
            {
                deletePict(p.PictIdent);
                pN.ErrCode    = -1;
                pN.ErrMessage = "Bildnummer saknas för aktuell servicerad";
                return(pN);
            }



            if (valid == -7)
            {
                pN.ErrCode    = -1;
                pN.ErrMessage = "Felaktig bildkategori (PictCatID) ";
                return(pN);
            }

            CServiceHuvud ch    = new CServiceHuvud();
            string        sOpen = ch.isOpen(ident, p.VartOrdernr);

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


            string sSql = "";

            sSql = getUpdateSQL(false);
            NxParameterCollection np = new NxParameterCollection();

            setParameters(np, p, false);

            string errText = "";

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

            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                pN.ErrCode    = -100;
                pN.ErrMessage = errText;
                return(pN);
            }

            return(p);
        }