/// <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); }
/// <summary> /// Reset export all Pyramid export /// settings for an order /// </summary> /// <param name="aVart_ordernr"></param> /// <param name="ident"></param> /// <returns>ErrorCL</returns> /// 2018-11-02 KJBO public ErrorCL resetExport(string aVart_ordernr, string ident) { ErrorCL err = new ErrorCL(); CReparator cr = new CReparator(); int identOK = cr.checkIdent(ident); if (identOK == -1) { err.ErrCode = -10; err.ErrMessage = "Ogiltigt login"; return(err); } ReparatorCL reparator = cr.getReparator(ident); vart_ordernr = aVart_ordernr; err = resendServHuv(ident); if (err.ErrCode != 0) { return(err); } err.ErrMessage = resetOrderArt(); if (err.ErrMessage != "") { err.ErrCode = -36102; return(err); } err.ErrMessage = resetReservdel(); if (err.ErrMessage != "") { err.ErrCode = -36103; return(err); } err.ErrMessage = resetServHuvRepTid(); if (err.ErrMessage != "") { err.ErrCode = -36104; return(err); } err.ErrMessage = resetServRadRepTid(); if (err.ErrMessage != "") { err.ErrCode = -36105; return(err); } // 2018-12-03 KJBO err.ErrMessage = pyrExp.resetPyramidExport(vart_ordernr); if (err.ErrMessage != "") { err.ErrCode = -36106; return(err); } pyrExp.addToPyramidChange(vart_ordernr, reparator.AnvID, 3); return(err); }