public NormsTiers SaveNormsTiers(NormsTiers tier)
        {
            SqlServerConnection conn = new SqlServerConnection();

            tier.Id = conn.SqlServerUpdate("DECLARE @item INT=" + tier.Item.Id + ", @catg INT= " + tier.Category.Id + " , @value INT=" + tier.Value + "; IF NOT EXISTS(SELECT nt_idnt FROM NormsTiers WHERE nt_item=@item AND nt_tctg=@catg) BEGIN INSERT INTO NormsTiers(nt_item, nt_tctg, nt_norm) output INSERTED.nt_idnt VALUES (@item, @catg, @value) END ELSE BEGIN UPDATE NormsTiers SET nt_item=@item, nt_tctg=@catg, nt_norm=@value output INSERTED.nt_idnt WHERE nt_item=@item AND nt_tctg=@catg END");

            return(tier);
        }
        public NormsView SaveNormItems(NormsView view)
        {
            SqlServerConnection conn = new SqlServerConnection();

            view.Item.Id = conn.SqlServerUpdate("DECLARE @idnt INT=" + view.Item.Id + ", @type INT=" + view.Item.Type.Id + ", @catg INT= " + view.Item.Category.Id + " , @name NVARCHAR(100)='" + view.Item.Name + "'; IF NOT EXISTS(SELECT ni_idnt FROM NormsItems WHERE ni_idnt=@idnt) BEGIN INSERT INTO NormsItems(ni_type, ni_catg, ni_item) output INSERTED.ni_idnt VALUES (@type, @catg, @name) END ELSE BEGIN UPDATE NormsItems SET ni_type=@type, ni_catg=@catg, ni_item=@name output INSERTED.ni_idnt WHERE ni_idnt=@idnt END");

            conn = new SqlServerConnection();
            SqlDataReader dr = conn.SqlServerConnect("SELECT fctg_idnt, fctg_level FROM FacilityCategory");

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    NormsTiers tier = new NormsTiers();
                    tier.Item     = new NormsItems(view.Item.Id);
                    tier.Category = new FacilityCategory(Convert.ToInt64(dr[0]));

                    if (Convert.ToInt64(dr[1]) == 1)
                    {
                        tier.Value = view.L1Norm;
                    }
                    else if (Convert.ToInt64(dr[1]) == 2)
                    {
                        tier.Value = view.L2Norm;
                    }
                    else if (Convert.ToInt64(dr[1]) == 3)
                    {
                        tier.Value = view.L3Norm;
                    }
                    else if (Convert.ToInt64(dr[1]) == 4)
                    {
                        tier.Value = view.L4Norm;
                    }
                    else if (Convert.ToInt64(dr[1]) == 5)
                    {
                        tier.Value = view.L5Norm;
                    }
                    else if (Convert.ToInt64(dr[1]) == 6)
                    {
                        tier.Value = view.L6Norm;
                    }

                    tier.Save();
                }
            }

            return(view);
        }