Example #1
0
        /// <summary>
        /// Saves a new PN to the database
        /// </summary>
        /// <param name="ident"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        /// 2019-04-04 KJBO
        public PnCL savePn(string ident, PnCL p)
        {
            PnCL resp = new PnCL();

            resp.ErrCode    = 0;
            resp.ErrMessage = "";
            CReparator cr      = new CReparator();
            int        identOK = cr.checkIdent(ident);

            if (identOK == -1)
            {
                resp.ErrCode    = -10;
                resp.ErrMessage = "Ogiltigt login";
                return(resp);
            }
            if (p.Pn == "")
            {
                resp.ErrCode    = -1;
                resp.ErrMessage = "Pn mÄste anges";
                return(resp);
            }

            string exists = pnExists(p.Pn);

            if (exists != "0" && exists != "1")
            {
                resp.ErrCode    = -100;
                resp.ErrMessage = "Fel vid kontroll av PN. Felmeddelande : " + exists;
                if (resp.ErrMessage.Length > 2000)
                {
                    resp.ErrMessage = resp.ErrMessage.Substring(1, 2000);
                }
                return(resp);
            }

            if (exists == "1")
            {
                resp.ErrCode    = 100;
                resp.ErrMessage = "Pn finns redan registrerat";
                return(resp);
            }

            string sSql = getInsertSql();
            NxParameterCollection pc = new NxParameterCollection();

            pc.Add("pn", p.Pn);
            pc.Add("reg", "System");
            pc.Add("regdat", System.DateTime.Now);
            string errText = "";
            int    iRc     = cdb.updateData(sSql, ref errText, pc);

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

                resp.ErrCode    = -100;
                resp.ErrMessage = errText;
                return(resp);
            }
            CComboValues cbv      = new CComboValues();
            List <PnCL>  respList = cbv.getPn("", p.Pn);

            if (respList.Count == 1)
            {
                return(respList[0]);
            }
            return(resp);
        }
Example #2
0
 /// <summary>
 /// Saves a new PN to the database
 /// </summary>
 /// <param name="ident"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 /// 2019-04-04 KJBO
 public PnCL savePn(string ident, PnCL p)
 {
     Basdata.CPn pn = new Basdata.CPn();
     return(pn.savePn(ident, p));
 }
Example #3
0
        public List <PnCL> getPn(string ident, string aPn)
        {
            List <PnCL> lp = new List <PnCL>();

            if (ident != "")
            {
                CReparator cr      = new CReparator();
                int        identOK = cr.checkIdent(ident);

                if (identOK == -1)
                {
                    PnCL p = new PnCL();
                    p.ErrCode    = -10;
                    p.ErrMessage = "Ogiltigt login";
                    lp.Add(p);
                    return(lp);
                }
            }

            string sSql = " select pn "
                          + " from pn ";

            if (aPn != "")
            {
                sSql += " where pn = :pn ";
            }
            sSql += " order by pn ";

            string errText           = "";
            NxParameterCollection pc = new NxParameterCollection();

            pc.Add("pn", aPn);
            DataTable dt = cdb.getData(sSql, ref errText, pc);

            int errCode = -100;

            if (errText == "" && dt.Rows.Count == 0)
            {
                errText = "Inga pn finns tillgÀngliga";
                errCode = 0;
            }

            if (errText != "")
            {
                if (errText.Length > 2000)
                {
                    errText = errText.Substring(1, 2000);
                }
                PnCL p = new PnCL();
                p.ErrCode    = errCode;
                p.ErrMessage = errText;
                lp.Add(p);
                return(lp);
            }


            foreach (DataRow dr in dt.Rows)
            {
                PnCL p = new PnCL();
                p.Pn         = dr["pn"].ToString();
                p.ErrCode    = 0;
                p.ErrMessage = "";
                lp.Add(p);
            }
            return(lp);
        }