Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Model.cs
Package: Visual.rar [view]
Upload User: yiyuerguo
Upload Date: 2014-09-27
Package Size: 3781k
Code Size: 2k
Category:
CSharp
Development Platform:
Others
- using System;
- using System.Drawing;
- using System.Collections;
- using System.Data;
- using System.Data.SqlClient;
- namespace photo
- {
- //模型类
- 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()
- {
- sqlConn=new SqlConnection("data source=Localhost;initial catalog=EAlbum;User ID=sa;Password=sa;");
- //连接数据库
- if(sqlConn.State == ConnectionState.Closed)
- sqlConn.Open();
- }
- //添加照片,参数file为文件名,cateid为照片属于的种类
- public void addphoto2(string file)
- {
- //将文件名为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_InsertPhoto2", 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();
- }
- }
- }