예제 #1
0
        /// <summary>
        /// Get a list of all reparators connected to an order
        /// </summary>
        /// <param name="VartOrdernr"></param>
        /// <param name="ident"></param>
        /// <returns></returns>
        /// 2018-02-02 KJBO
        public List <ShReparatorCL> getShReparatorList(string VartOrdernr, string ident)
        {
            List <ShReparatorCL> shRepList = new List <ShReparatorCL>();
            string sSql = "SELECT id, vart_ordernr, AnvID "
                          + " FROM shReparator "
                          + " where vart_ordernr = :vart_ordernr ";
            NxParameterCollection pc = new NxParameterCollection();

            pc.Add("vart_ordernr", VartOrdernr);
            ErrorCL   err = new ErrorCL();
            DataTable dt  = cdb.getData(sSql, ident, ref err, pc);

            if (err.ErrCode != 0)
            {
                ShReparatorCL shRep = new ShReparatorCL();
                shRep.ErrCode    = err.ErrCode;
                shRep.ErrMessage = err.ErrMessage;
                shRepList.Add(shRep);
                return(shRepList);
            }

            foreach (DataRow dr in dt.Rows)
            {
                ShReparatorCL shRep = new ShReparatorCL();
                shRep.Id          = Convert.ToInt32(dr["id"]);
                shRep.VartOrdernr = dr["vart_ordernr"].ToString();
                shRep.AnvID       = dr["AnvID"].ToString();
                shRepList.Add(shRep);
            }
            return(shRepList);
        }
예제 #2
0
        /// <summary>
        /// Creates a list of all active reparatör
        /// in alphabetic order. To be used by dropdown controls
        /// or elsewhere when a key-value collection is needed
        /// </summary>
        /// <param name="ident"></param>
        /// <returns></returns>
        public List <ListRepCL> getReparatorList(string ident)
        {
            List <ListRepCL> repList = new List <ListRepCL>();
            string           sSql    = " SELECT AnvID, reparator "
                                       + " FROM reparator "
                                       + " where visas = true "
                                       + " order by reparator ";
            ErrorCL   err = new ErrorCL();
            DataTable dt  = cdb.getData(sSql, ident, ref err, null);

            if (err.ErrCode != 0)
            {
                ListRepCL rep = new ListRepCL();
                rep.ErrCode    = err.ErrCode;
                rep.ErrMessage = err.ErrMessage;
                repList.Add(rep);
                return(repList);
            }

            foreach (DataRow dr in dt.Rows)
            {
                ListRepCL rep = new ListRepCL();
                rep.ErrCode    = 0;
                rep.ErrMessage = "";
                rep.AnvId      = dr["AnvID"].ToString();
                rep.Reparator  = dr["reparator"].ToString();
                repList.Add(rep);
            }

            return(repList);
        }
예제 #3
0
        public DataTable getData(string sSql, string ident, ref ErrorCL err, NxParameterCollection pc)
        {
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

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

            string    errText = "";
            DataTable dt      = getData(sSql, ref errText, pc);

            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                err.ErrMessage = errText;
                err.ErrCode    = -100;
                return(null);
            }
            return(dt);
        }
예제 #4
0
        /// <summary>
        /// Returns a list of customers in a key-value pair
        /// To be used by dropdowns or similar
        /// </summary>
        /// <param name="ident"></param>
        /// <returns></returns>
        public List <ListKundCL> getCustList(string ident)
        {
            List <ListKundCL> custList = new List <ListKundCL>();
            string            sSql     = " select kund_id, kund + ', ' + coalesce(stad,'') + ', ' + foretagskod kund "
                                         + " from kund "
                                         + " where kund_id <> '' "
                                         + " and foretagskod is not null "
                                         + " order by kund ";

            ErrorCL err = new ErrorCL();

            DataTable dt = cdb.getData(sSql, ident, ref err, null);

            if (err.ErrCode != 0)
            {
                ListKundCL cust = new ListKundCL();
                cust.ErrCode    = err.ErrCode;
                cust.ErrMessage = err.ErrMessage;
                custList.Add(cust);
                return(custList);
            }

            foreach (DataRow dr in dt.Rows)
            {
                ListKundCL cust = new ListKundCL();
                cust.ErrCode    = 0;
                cust.ErrMessage = "";
                cust.kund_id    = dr["kund_id"].ToString();
                cust.kund       = dr["kund"].ToString();
                custList.Add(cust);
            }

            return(custList);
        }
예제 #5
0
        private void resendToPyramid()
        {
            String sSql = " select vart_ordernr "
                          + " from serviceHuvud "
                          + " where SentToPyramid = false ";
            String    errStr = "";
            DataTable dt     = cdb.getData(sSql, ref errStr);

            ExportToPyramid.CExportToPyramid expPyr = new ExportToPyramid.CExportToPyramid();
            foreach (DataRow dr in dt.Rows)
            {
                ServHuvCL sh = new ServHuvCL();
                sh.Vart_ordernr = dr["vart_ordernr"].ToString();
                sh = getServiceHuvud(sh);
                ErrorCL errCl = expPyr.exportOrder(sh);
            }
        }
예제 #6
0
        private ErrorCL checkOutIfNeeded(string ident, ReservdelCL res)
        {
            ErrorCL err = new ErrorCL();

            err.ErrCode    = 0;
            err.ErrMessage = "";
            Decimal onOrder    = 0;
            Decimal outChecked = 0;

            if (isDotArticle(res.Artnr))
            {
                return(err);
            }
            string errStr   = "";
            int    kategori = getArtKat(res.Artnr, ref errStr);

            if (kategori != 1)
            {
                return(err);
            }
            if (errStr == "")
            {
                onOrder = countArtOnOrder(res, ref errStr);
            }
            if (errStr == "")
            {
                outChecked = countOutchecked(res, ref errStr);
            }
            if (errStr != "")
            {
                err.ErrMessage = errStr;
                if (err.ErrMessage != "")
                {
                    err.ErrCode = 13101;
                }
                return(err);
            }
            if (onOrder > outChecked)
            {
                OrderArtCL oaCL = checkoutOrderArt(ident, res, onOrder - outChecked);
                if (oaCL.ErrCode != 0)
                {
                    err.ErrMessage = oaCL.ErrMessage;
                    err.ErrCode    = oaCL.ErrCode;
                    return(err);
                }


                // Added 2018-08-27. Reservdel shall now be confirmed in Pyramid
                if (!res.getFromCS)
                {
                    List <ArticleCommit.CArticleCommitData> acList = new List <ArticleCommit.CArticleCommitData>();
                    ArticleCommit.CArticleCommitData        ac     = new ArticleCommit.CArticleCommitData();
                    ac.articleNumber = res.Artnr;
                    ac.orderNumber   = res.VartOrdernr;
                    ac.quantity      = onOrder - outChecked;
                    ac.orderArtID    = oaCL.OrderArtId;
                    acList.Add(ac);
                    ArticleCommit.CArticleCommit acCommit = new ArticleCommit.CArticleCommit();
                    err = acCommit.generateFile(acList, "1");
                    //ac.sav
                }

                // Removed 2018-08-27 and replaced by the code above.

                //if (!res.getFromCS)
                //{
                //    CompactStore.updateOAStorageData data = new CompactStore.updateOAStorageData();
                //    data.orderArtId = oaCL.OrderArtId;
                //    //data.stockToSend = Convert.ToInt32(oaCL.OrdAntal);
                //    data.stockToSend = res.Antal;
                //    data.error = "";
                //    CompactStore.CCompactStore cs = new CompactStore.CCompactStore();
                //    string result = cs.updateDbWithoutSend(data, "x");
                //}
            }
            return(err);
        }
예제 #7
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));
        }
예제 #8
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);
        }
예제 #9
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);
        }