http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3305|回复: 1

[学生提问] C#可访问性不一致

[复制链接]
发表于 2015-3-17 17:11:47 | 显示全部楼层 |阅读模式
16金钱
飞哥,我运行程序的时候出现了如图这样的问题,麻烦你帮我看一下该怎么解决,先谢谢啦
using System;
using System.Drawing;
using System.Collections;
using System.Data;
using System.Data.SqlClient;


namespace 系统
{
    public class Model
    {
        //定义了一系列的列表,用于存储从数据库中取出的数据
        public ArrayList idList, categoryList, nameList, descList, searchMark, albumList, timeList, observer;
        private SqlConnection sqlConn;
        //图片类型
        public Image image;
        //标识结点位置
        public int ListIndex;


        //析构函数,用于关闭与数据库的连接
        ~Model()
        {
            if (sqlConn.State == ConnectionState.Open)
                sqlConn.Close();
        }


        //构造函数,初始化、实例化Model类中的成员变量
        public Model()
        {
            ListIndex = -1;


            observer = new ArrayList();
            idList = new ArrayList();
            albumList = new ArrayList();
            categoryList = new ArrayList();
            nameList = new ArrayList();
            descList = new ArrayList();
            searchMark = new ArrayList();
            timeList = new ArrayList();


            albumList.Add("家庭");
            albumList.Add("朋友");
            albumList.Add("同事");
            albumList.Add("风景");
            albumList.Add("其他");
            string conStr = @"Data Source=127.0.0.1;Initial Catalog=db_毕业论文ersist Security Info=True;User ID=sa;pwd=zack931104";
            sqlConn = new SqlConnection(conStr);


            //连接数据库
            if (sqlConn.State == ConnectionState.Closed)
                sqlConn.Open();


            if (sqlConn.State == ConnectionState.Open)
            {
                SqlCommand sqlCmd = new SqlCommand("SELECT category, [id] AS PhotoID, [name] AS Photo, [desc] AS Photo_Desc,[time] AS Photo_Time FROM Photos ", sqlConn);


                SqlDataReader sqlPhotoAlbum = sqlCmd.ExecuteReader();


                //将除图片本身以外的数据库表Photos中的信息全部取出,放在事先定义的列表中
                while (sqlPhotoAlbum.Read())
                {
                    idList.Add((int)sqlPhotoAlbum["hotoID"]);
                    nameList.Add(sqlPhotoAlbum["hoto"].ToString());
                    descList.Add(sqlPhotoAlbum["hoto_Desc"].ToString());
                    timeList.Add(sqlPhotoAlbum["hoto_Time"].ToString());
                    categoryList.Add((int)sqlPhotoAlbum["category"]);
                    //每添加一项就给对应的项做一个标记,为查找作准备
                    searchMark.Add(0);
                }
                sqlPhotoAlbum.Close();
            }
        }


        //用来向模型中登记观察者,o是一个view的实例
        public void registerObserver(Observer o)
        {
            observer.Add(o);
        }


        // 用来向模型中注销观察者.
        public void removeObserver(Observer o)
        {
            observer.Remove(o);
        }


        //通知视图进行更新操作,str代表操作的类型,npara为此操作的参数(只在添加时有用)
        private void dataUpdate(string str, int npara)
        {
            for (int i = 0; i < observer.Count; i++)
            {
                ((Observer)observer).dataUpdate(this, str, npara);
            }
        }




        /*下面定义了一系列对数据的操作
         * 包括照片的选取、查找、删除、添加和照片属性的更新
         * 这里用数字1、2、3、4、5分别表示这相应的5种操作
         * */


        //选取,index为此照片在数据库中的ID——对应着picture的数据的改变(PictureBox)
        public void select(int index)
        {
            ListIndex = -1;
            image = null;


            //没有选取照片
            if (index < 0)
            {
                dataUpdate("1", 0);
                return;
            }
            //将被选中的照片的ID和已经取出的所有照片相比,
            //如果匹配则记下它的索引值——ListIndex——在整个列表中的序号
            for (int i = 0; i < nameList.Count; i++)
            {
                if (((int)idList) == index)
                {
                    ListIndex = i;
                    break;
                }
            }
            //从数据库中取出此照片,放在image中
            string strCmd = String.Format("SELECT photo FROM Photos WHERE id = {0}", index);
            SqlCommand cmd = new SqlCommand(strCmd, sqlConn);


            byte[] b = (byte[])cmd.ExecuteScalar();
            if (b.Length > 0)
            {
                System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
                stream.Write(b, 0, b.Length);


                image = new Bitmap(stream);


                stream.Close();
            }
            //更新
            dataUpdate("1", 0);
        }
        public void search(int index, string str)
        {
            //照片名称
            if (index == 0)
            {
                for (int i = 0; i < nameList.Count; i++)
                {
                    //如果在nameList中匹配到用户输入的关键字则将这个纪录对应的searchMark置为1(初始化时是0)
                    if (((string)nameList).IndexOf(str) > -1)
                        searchMark = 1;
                    else
                        searchMark = 0;
                }
            }
            //照相时间
            if (index == 1)
            {
                for (int i = 0; i < timeList.Count; i++)
                {
                    //如果在timeList中匹配到用户输入的关键字则将这个纪录对应的searchMark置为1(初始化时是0)
                    if (((string)timeList).IndexOf(str) > -1)
                        searchMark = 1;
                    else
                        searchMark = 0;
                }
            }
            //描述信息
            if (index == 2)
            {
                for (int i = 0; i < descList.Count; i++)
                {
                    //如果在descList中匹配到用户输入的关键字则将这个纪录对应的searchMark置为1(初始化时是0)
                    if (((string)descList).IndexOf(str) > -1)
                        searchMark = 1;
                    else
                        searchMark = 0;
                }
            }


            dataUpdate("2", 0);
        }
        public void update(string newname, string newtime, string newdesc)
        {
            if (ListIndex < 0)
                return;


            string strCmd = String.Format("UPDATE Photos SET [name] = '{0}',[time]='{1}',[desc]='{2}' WHERE id = {3}", newname, newtime, newdesc, idList[ListIndex]);


            //在列表中更新
            nameList[ListIndex] = newname;
            timeList[ListIndex] = newtime;
            descList[ListIndex] = newdesc;


            //在数据库中更新
            SqlCommand cmd = new SqlCommand(strCmd, sqlConn);
            cmd.ExecuteNonQuery();
            dataUpdate("5", 0);


        }
        public int addphoto(string file, int cateid)
        {
            //将文件名为file的文件读入到buffer中
            System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            byte[] buffer = new byte[stream.Length];
            stream.Read(buffer, 0, (int)stream.Length);
            stream.Close();


            string strName = System.IO.Path.GetFileNameWithoutExtension(file);


            //调用sp_InsertPhoto存储过程,添加照片
            SqlCommand cmd = new SqlCommand("sp_InsertPhoto", sqlConn);
            cmd.CommandType = CommandType.StoredProcedure;


            SqlParameter param = cmd.Parameters.Add("RETURN_VALUE", SqlDbType.Int);
            param.Direction = ParameterDirection.ReturnValue;


            cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = strName;
            cmd.Parameters.Add("@image", SqlDbType.Image).Value = buffer;
            cmd.Parameters.Add("@album", SqlDbType.Int).Value = cateid;


            cmd.ExecuteNonQuery();


            //获得返回的照片ID
            int nID = (int)cmd.Parameters["RETURN_VALUE"].Value;


            //将照片添加到列表中
            idList.Add(nID);
            nameList.Add(strName);
            descList.Add("");
            searchMark.Add(0);
            categoryList.Add(cateid);
            timeList.Add("");


            //buffer清空
            buffer = null;


            //更新视图,cateid参数表示照片属于的种类
            dataUpdate("4", cateid);
            return nID;
        }
        public int deletephoto()
        {
            //没有选定照片或数据库中没有照片,不执行任何删除操作
            if (ListIndex < 0 || idList.Count == 0)
                return ListIndex;


            //取出照片的ID,从数据库中删除
            int index = (int)(idList[ListIndex]);
            string strCmd = String.Format("DELETE FROM Photos WHERE id = {0}", index);


            SqlCommand cmd = new SqlCommand(strCmd, sqlConn);
            cmd.ExecuteNonQuery();


            //把所有列表中关于此照片的数据删除
            idList.RemoveAt(ListIndex);
            nameList.RemoveAt(ListIndex);
            descList.RemoveAt(ListIndex);
            categoryList.RemoveAt(ListIndex);
            searchMark.RemoveAt(ListIndex);
            timeList.RemoveAt(ListIndex);


            image = null;
            int revalue = ListIndex;
            //将“指针”指向被删除照片的前一张照片
            ListIndex--;
            dataUpdate("3", ListIndex);
            return revalue;


        }
    }
}
using System;
using System.Windows.Forms;
namespace 系统
{
    public enum TextType { name, time, desc };

    //显示照片名称、照相时间和描述信息,继承了 TextBox,Observer两个类
    public class Attribute : TextBox, Observer
    {
        private Model model;
        public TextType type;

        //构造函数
        public Attribute()
        {
        }

        //实现自己的dataUpdate
        public void dataUpdate(Model model, string str, int npara)
        {
            this.model = model;
            DrawText();
        }

        //设置视图对应的模型
        public void SetModel(Model model)
        {
            this.model = model;
        }

        //重画
        private void DrawText()
        {
            int index = model.ListIndex;
            if (index >= 0 && model.nameList.Count > 0)
            {
                if (this.type == TextType.name)
                    this.Text = (string)model.nameList[index];
                else if (this.type == TextType.desc)
                    this.Text = (string)model.descList[index];
                else if (this.type == TextType.time)
                    this.Text = (string)model.timeList[index];
            }
            else
                this.Text = "";
        }

    }
}



捕获e.PNG

最佳答案

查看完整内容

把方法的访问性都改为public就行了


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2015-3-17 17:11:48 | 显示全部楼层
把方法的访问性都改为public就行了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-29 01:39

© 2014-2021

快速回复 返回顶部 返回列表