Пример #1
0
        /// <summary>
        /// Updates the drawing metadata.
        /// Note that the drawing must exist, identified
        /// by the following properties in the drawing class:
        /// ventil_id, DrawingNo.
        /// For performance reason this method does not evaluate
        /// the drawing size.
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        /// 2019-05-27 KJBO
        public DrawingCL updateDrawingMetaData(string ident, DrawingCL d)
        {
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            // Creates a class to return an error
            DrawingCL cdRet = new DrawingCL();

            if (identOK == -1)
            {
                cpict.deletePict(d.DrawingIdent);
                cdRet.ErrCode    = -10;
                cdRet.ErrMessage = "Ogiltigt login";
                return(cdRet);
            }

            // Init variable
            string err   = "";
            int    valid = validateDrawing(d, true, ref err);

            if (valid == -1 || valid == -4)
            {
                cpict.deletePict(d.DrawingIdent);
                cdRet.ErrCode    = -1;
                cdRet.ErrMessage = "VentilId saknas eller felaktigt";
                return(cdRet);
            }

            if (valid == -2 || valid == -3)
            {
                cdRet.ErrCode    = -1;
                cdRet.ErrMessage = "Ritningsnummer saknas eller är felaktigt";
                return(cdRet);
            }



            string sSql = "";

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

            setParameters(np, d, false);

            string errText = "";

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

            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                cdRet.ErrCode    = -100;
                cdRet.ErrMessage = errText;
                return(cdRet);
            }
            return(d);
        }
Пример #2
0
        private int getNextDrawinNo(DrawingCL d)
        {
            string sSql = " select coalesce(max(DrawingNo),0) as maxDrawingNo "
                          + " from valveDrawing "
                          + " where ventil_id = :ventil_id ";

            NxParameterCollection pc = new NxParameterCollection();

            pc.Add("ventil_id", d.ventil_id);
            string    err = "";
            DataTable dt  = cdb.getData(sSql, ref err, pc);

            return(Convert.ToInt32(dt.Rows[0]["maxDrawingNo"]) + 1);
        }
Пример #3
0
        /// <summary>
        /// Set parameters function
        /// </summary>
        /// <param name="np"></param>
        /// <param name="d"></param>
        /// <param name="retrieveDrawing"></param>
        private void setParameters(NxParameterCollection np, DrawingCL d, Boolean retrieveDrawing)
        {
            long fileSize = 0;

            np.Add("ventil_id", d.ventil_id);
            np.Add("drawingNo", d.DrawingNo);
            np.Add("drawingDescr", d.Description);
            np.Add("fileType", d.FileType);
            if (retrieveDrawing)
            {
                np.Add("drawing", getDrawing(d.DrawingIdent, ref fileSize));
                np.Add("drawingSize", fileSize);
                d.DrawingSize = fileSize;
            }
        }
Пример #4
0
        private int validateDrawing(DrawingCL d, bool forDelete, ref string err)
        {
            if (string.IsNullOrEmpty(d.ventil_id))
            {
                return(-1);
            }
            if (forDelete)
            {
                if (d.DrawingNo == 0)
                {
                    return(-2);
                }
            }
            if (forDelete || d.DrawingNo > 0)
            {
                if (!drawingExists(d.ventil_id, d.DrawingNo))
                {
                    return(-3);
                }
            }
            else if (d.DrawingNo == 0)
            {
                CVentil v     = new CVentil();
                string  dummy = "";
                if (v.validateVentilID(d.ventil_id, ref dummy) == 0)
                {
                    return(-4);
                }
            }
            if (!forDelete)
            {
                if (!cpict.validatePictIdent(d.DrawingIdent))
                {
                    return(-5);
                }
            }

            return(1);
        }
Пример #5
0
        /// <summary>
        /// Deletes a drawing from the database. The drawing is
        /// identified by ventil_id and drawingNo (PK).
        /// Return value is a DrawingCl with errCode = 0
        /// and errMessage as an empty string. On error
        /// the errCode is not 0 and the errMessage tells
        /// what was going wrong
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        /// 2019-05-15 KJBO
        public DrawingCL deleteDrawing(string ident, DrawingCL d)
        {
            CDrawing cd = new CDrawing();

            return(cd.deleteDrawing(ident, d));
        }
Пример #6
0
        /// <summary>
        /// Updates the drawing metadata.
        /// Note that the drawing must exist, identified
        /// by the following properties in the drawing class:
        /// ventil_id, DrawingNo.
        /// For performance reason this method does not evaluate
        /// the drawing size.
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        /// 2019-05-27 KJBO
        public DrawingCL updateDrawingMetaData(string ident, DrawingCL d)
        {
            CDrawing cd = new CDrawing();

            return(cd.updateDrawingMetaData(ident, d));
        }
Пример #7
0
        /// <summary>
        /// Save a previous uploaded drawing to database
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        public DrawingCL saveDrawing(string ident, DrawingCL d)
        {
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            // Creates a class to return an error
            DrawingCL cdRet = new DrawingCL();

            if (identOK == -1)
            {
                cpict.deletePict(d.DrawingIdent);
                cdRet.ErrCode    = -10;
                cdRet.ErrMessage = "Ogiltigt login";
                return(cdRet);
            }

            // Init variable
            string err   = "";
            int    valid = validateDrawing(d, false, ref err);

            if (valid == -1 || valid == -4)
            {
                cpict.deletePict(d.DrawingIdent);
                cdRet.ErrCode    = -1;
                cdRet.ErrMessage = "VentilId saknas eller felaktigt";
                return(cdRet);
            }

            if (valid == -5)
            {
                cdRet.ErrCode    = -1;
                cdRet.ErrMessage = "Ritning saknas i uppladdningbiblioteket";
                return(cdRet);
            }



            string sSql = "";

            if (d.DrawingNo == 0)
            {
                d.DrawingNo = getNextDrawinNo(d);
                sSql        = getInsertSql();
            }
            else
            {
                sSql = getUpdateSQL(true);
            }
            NxParameterCollection np = new NxParameterCollection();

            setParameters(np, d, true);

            string errText = "";

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

            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                cdRet.ErrCode    = -100;
                cdRet.ErrMessage = errText;
                return(cdRet);
            }
            cpict.deletePict(d.DrawingIdent);
            return(d);
        }
Пример #8
0
        /// <summary>
        /// This method returns all drawings for one ventil
        /// Note that you dont get the actual drawing nor the
        /// drawingIdent. Instead you use this method for getting a
        /// list of available drawings (and also gets the drawing
        /// description).
        /// After that you have to call GetDrawing and DownloadDrawing
        /// in turn in order to get each individual drawing.
        /// The reason for this is performance. This method gives
        /// a fast list of available drawings only.
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="vartOrdernr"></param>
        /// <param name="radnr"></param>
        /// <returns></returns>
        /// 2016-03-11 Pergas AB kjbo
        public List <DrawingCL> getDrawingsForVentil(string ident, string ventilId)
        {
            List <DrawingCL> dList = new List <DrawingCL>();

            CReparator cr = new CReparator();

            int identOK = cr.checkIdent(ident);

            if (identOK == -1)
            {
                DrawingCL d = new DrawingCL();
                d.ErrCode    = -10;
                d.ErrMessage = "Ogiltigt login";
                dList.Add(d);
                return(dList);
            }


            string sSql = "SELECT ventil_id, drawingNo, drawingDescr, drawingSize, fileType "
                          + "  FROM valveDrawing "
                          + " where ventil_id = :ventil_id ";

            NxParameterCollection np = new NxParameterCollection();

            np.Add("ventil_id", ventilId);

            string errText = "";

            DataTable dt = cdb.getData(sSql, ref errText, np);

            int errCode = -100;

            if (errText == "" && dt.Rows.Count == 0)
            {
                errText = "Det finns inga ritningar för aktuell ventil";
                errCode = 0;
            }


            if (errText != "")
            {
                DrawingCL d = new DrawingCL();
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                d.ErrCode    = errCode;
                d.ErrMessage = errText;
                dList.Add(d);
                return(dList);
            }


            foreach (DataRow dr in dt.Rows)
            {
                DrawingCL d = new DrawingCL();
                d.Description  = dr["drawingDescr"].ToString();
                d.DrawingNo    = Convert.ToInt32(dr["drawingNo"]);
                d.DrawingSize  = Convert.ToInt64(dr["drawingSize"]);
                d.ErrCode      = 0;
                d.ErrMessage   = "";
                d.FileType     = dr["fileType"].ToString();
                d.ventil_id    = dr["ventil_id"].ToString();
                d.DrawingIdent = "";
                dList.Add(d);
            }

            return(dList);
        }
Пример #9
0
        /// <summary>
        /// Deletes a drawing from the database. The drawing is
        /// identified by ventil_id and drawingNo (PK).
        /// Return value is a DrawingCl with errCode = 0
        /// and errMessage as an empty string. On error
        /// the errCode is not 0 and the errMessage tells
        /// what was going wrong
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        /// 2019-05-15 KJBO
        public DrawingCL deleteDrawing(string ident, DrawingCL d)
        {
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            // Creates a class to return an error
            DrawingCL drRet = new DrawingCL();

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

            // Init variable
            string err   = "";
            int    valid = validateDrawing(d, true, ref err);

            if (valid == -1 || valid == -2)
            {
                drRet.ErrCode    = -1;
                drRet.ErrMessage = "Both ventilId and drawingNo must be provided";
                return(drRet);
            }

            if (valid == -3)
            {
                drRet.ErrCode    = -1;
                drRet.ErrMessage = "Drawing not found";
                return(drRet);
            }


            string sSql = " delete from valveDrawing "
                          + " where ventil_id = :ventil_id "
                          + " and drawingNo = :drawingNo ";

            NxParameterCollection np = new NxParameterCollection();

            setParameters(np, d, false);

            string errText = "";

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

            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                drRet.ErrCode    = -100;
                drRet.ErrMessage = errText;
                return(drRet);
            }
            d.Description  = "";
            d.DrawingIdent = "";
            d.DrawingNo    = 0;
            d.DrawingSize  = 0;
            d.ErrCode      = 0;
            d.ErrMessage   = "";
            d.FileType     = "";
            d.ventil_id    = "";
            return(d);
        }
Пример #10
0
        /// <summary>
        /// Get a drawing from the database identified by
        /// primary key (ventil_id, drawingNo)
        /// Returns a DrawingCL object with the drawingIdent
        /// field with a file name to the file being extracted
        /// by the server.
        /// If the fileName is empty or begins with -1 then
        /// there is an error while extracting the picture from
        /// the database to the temporary storage
        ///
        /// After this function is called there has to be a call
        /// to downloadDrawing with the drawingIdent as parameter
        /// This function returns the drawing to the caller as
        /// a memoryStream
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="ventilId"></param>
        /// <param name="ritningNo"></param>
        /// <returns></returns>
        public DrawingCL getDrawing(string ident, string ventilId, int ritningNo)
        {
            DrawingCL  d  = new DrawingCL();
            CReparator cr = new CReparator();

            int identOK = cr.checkIdent(ident);

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

            string sSql = "SELECT ventil_id, drawingNo, drawing, drawingDescr, drawingSize, fileType "
                          + "  FROM valveDrawing "
                          + " where ventil_id = :ventil_id "
                          + " and drawingNo = :drawingNo ";


            NxParameterCollection np = new NxParameterCollection();

            np.Add("ventil_id", ventilId);
            np.Add("drawingNo", ritningNo);

            string errText = "";

            DataTable dt = cdb.getData(sSql, ref errText, np);

            int errCode = -100;

            if (errText == "" && dt.Rows.Count == 0)
            {
                errText = "Felaktig ritningsidentitet";
                errCode = 0;
            }


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


            DataRow dr = dt.Rows[0];

            d.ErrCode    = 0;
            d.ErrMessage = "";
            string error    = "";
            long   fileSize = 0;

            if (dr["drawing"] != DBNull.Value)
            {
                byte[]       data = (byte[])dr["drawing"];
                MemoryStream ms   = new MemoryStream(data);
                d.DrawingIdent = saveDrawingToFile(ms, ref error, ref fileSize);
            }
            if (error != "")
            {
                d.ErrCode    = -1;
                d.ErrMessage = error;
                return(d);
            }
            d.Description = dr["drawingDescr"].ToString();
            d.DrawingNo   = Convert.ToInt32(dr["drawingNo"]);
            d.DrawingSize = Convert.ToInt64(dr["drawingSize"]);
            d.FileType    = dr["fileType"].ToString();
            d.ventil_id   = dr["ventil_id"].ToString();
            return(d);
        }