Flex上传图片等信息到数据库,并下载显示图片
2011-11-14 19:51 186人阅读 评论(0) 收藏 举报
1.上传到SqlServer
功能为上传漫画至SqlServer,先上传非二进制图片信息(漫画编号,卷数,本卷图片编号),上传成功后根据返回的自增 主键再上传二进制图片.
采用FluorineFx调用RemoteObject操作数据库,上传图片则采用FileReference上传到UploadManHua.ashx
C#端远程服务类 ManHuaService.cs
Code using System;
using System.Collections.Generic; using System.Text; using System.Data;
using System.Data.SqlClient; using FluorineFx; using FluorineFx.AMF3;
namespace ServiceLibrary {
[RemotingService(\)] public class ManHuaService {
[DataTableType(\)] ///
///
///
/// ///
public ManHuaTuPian GetOneManHuaTuPian(int ManHuaID, int JuanShu, int BenJuanTuPianXH) {
SqlConnection con = new SqlConnection(%uaLiuLan\); con.Open();
SqlCommand cmd = new SqlCommand(\nHuaID=\ + ManHuaID.ToString() + \ + JuanShu.ToString() + %uanTuPianXH=\ + BenJuanTuPianXH.ToString(), con); SqlDataAdapter dap = new SqlDataAdapter(cmd); DataTable tb = new DataTable(); dap.Fill(tb); con.Close();
if (tb.Rows.Count > 0) {
ManHuaTuPian objManHua = new ManHuaTuPian(); objManHua.ID = int.Parse(tb.Rows[0][\].ToString());
objManHua.ManHuaID = int.Parse(tb.Rows[0][\].ToString()); objManHua.JuanShu = int.Parse(tb.Rows[0][\].ToString());
objManHua.BenJuanTuPianXH = int.Parse(tb.Rows[0][\].ToString());
byte[] bytes = (byte[])tb.Rows[0][\]; ByteArray imagebytes = new ByteArray(); imagebytes.WriteBytes(bytes,0,bytes.Length); objManHua.TuPian = imagebytes; return objManHua; } else return null; }
///
/// 插入一张漫画图片 ///
/// ///
/// ///
public int InsertManHua(int ManHuaID,int JuanShu,int BenJuanTuPianXH) {
SqlConnection con = new SqlConnection(%uaLiuLan\); con.Open();
SqlCommand cmd = new SqlCommand(); cmd.Connection = con;
cmd.CommandText = %uPianXH) values(@ManHuaID,@JuanShu,@BenJuanTuPianXH)\\r\\nselect scope_identity()\;
SqlParameterCollection sqlParams = cmd.Parameters; sqlParams.Add(\, SqlDbType.Int); sqlParams.Add(\, SqlDbType.Int);
sqlParams.Add(\, SqlDbType.Int); sqlParams[0].Value = ManHuaID; sqlParams[1].Value = JuanShu;
sqlParams[2].Value = BenJuanTuPianXH; int identityID;
identityID = int.Parse(cmd.ExecuteNonQuery().ToString()); con.Close(); con.Dispose(); return identityID; }
///
///
///
///
SqlConnection con = new SqlConnection(%uaLiuLan\); con.Open();
SqlCommand cmd = new SqlCommand(%uPian where ID=@ID\, con);
cmd.Parameters.Add(new SqlParameter(\, imagebytes)); cmd.Parameters.Add(new SqlParameter(\, ID)); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } } }
1.上传二进制和其它信息到数据库 上传界面
UploadManHua.mxml:
Code